[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 4/6] mm: replace vma->vm_flags indirect modification in ksm_madvise
- To: Suren Baghdasaryan <surenb@xxxxxxxxxx>
- From: Mike Rapoport <rppt@xxxxxxxxxx>
- Date: Thu, 26 Jan 2023 11:26:58 +0200
- Cc: akpm@xxxxxxxxxxxxxxxxxxxx, michel@xxxxxxxxxxxxxx, jglisse@xxxxxxxxxx, mhocko@xxxxxxxx, vbabka@xxxxxxx, hannes@xxxxxxxxxxx, mgorman@xxxxxxxxxxxxxxxxxxx, dave@xxxxxxxxxxxx, willy@xxxxxxxxxxxxx, liam.howlett@xxxxxxxxxx, peterz@xxxxxxxxxxxxx, ldufour@xxxxxxxxxxxxx, paulmck@xxxxxxxxxx, luto@xxxxxxxxxx, songliubraving@xxxxxx, peterx@xxxxxxxxxx, david@xxxxxxxxxx, dhowells@xxxxxxxxxx, hughd@xxxxxxxxxx, bigeasy@xxxxxxxxxxxxx, kent.overstreet@xxxxxxxxx, punit.agrawal@xxxxxxxxxxxxx, lstoakes@xxxxxxxxx, peterjung1337@xxxxxxxxx, rientjes@xxxxxxxxxx, axelrasmussen@xxxxxxxxxx, joelaf@xxxxxxxxxx, minchan@xxxxxxxxxx, jannh@xxxxxxxxxx, shakeelb@xxxxxxxxxx, tatashin@xxxxxxxxxx, edumazet@xxxxxxxxxx, gthelen@xxxxxxxxxx, gurua@xxxxxxxxxx, arjunroy@xxxxxxxxxx, soheil@xxxxxxxxxx, hughlynch@xxxxxxxxxx, leewalsh@xxxxxxxxxx, posk@xxxxxxxxxx, will@xxxxxxxxxx, aneesh.kumar@xxxxxxxxxxxxx, npiggin@xxxxxxxxx, chenhuacai@xxxxxxxxxx, tglx@xxxxxxxxxxxxx, mingo@xxxxxxxxxx, bp@xxxxxxxxx, dave.hansen@xxxxxxxxxxxxxxx, richard@xxxxxx, anton.ivanov@xxxxxxxxxxxxxxxxxx, johannes@xxxxxxxxxxxxxxxx, qianweili@xxxxxxxxxx, wangzhou1@xxxxxxxxxxxxx, herbert@xxxxxxxxxxxxxxxxxxx, davem@xxxxxxxxxxxxx, vkoul@xxxxxxxxxx, airlied@xxxxxxxxx, daniel@xxxxxxxx, maarten.lankhorst@xxxxxxxxxxxxxxx, mripard@xxxxxxxxxx, tzimmermann@xxxxxxx, l.stach@xxxxxxxxxxxxxx, krzysztof.kozlowski@xxxxxxxxxx, patrik.r.jakobsson@xxxxxxxxx, matthias.bgg@xxxxxxxxx, robdclark@xxxxxxxxx, quic_abhinavk@xxxxxxxxxxx, dmitry.baryshkov@xxxxxxxxxx, tomba@xxxxxxxxxx, hjc@xxxxxxxxxxxxxx, heiko@xxxxxxxxx, ray.huang@xxxxxxx, kraxel@xxxxxxxxxx, sre@xxxxxxxxxx, mcoquelin.stm32@xxxxxxxxx, alexandre.torgue@xxxxxxxxxxx, tfiga@xxxxxxxxxxxx, m.szyprowski@xxxxxxxxxxx, mchehab@xxxxxxxxxx, dimitri.sivanich@xxxxxxx, zhangfei.gao@xxxxxxxxxx, jejb@xxxxxxxxxxxxx, martin.petersen@xxxxxxxxxx, dgilbert@xxxxxxxxxxxx, hdegoede@xxxxxxxxxx, mst@xxxxxxxxxx, jasowang@xxxxxxxxxx, alex.williamson@xxxxxxxxxx, deller@xxxxxx, jayalk@xxxxxxxxxxxx, viro@xxxxxxxxxxxxxxxxxx, nico@xxxxxxxxxxx, xiang@xxxxxxxxxx, chao@xxxxxxxxxx, tytso@xxxxxxx, adilger.kernel@xxxxxxxxx, miklos@xxxxxxxxxx, mike.kravetz@xxxxxxxxxx, muchun.song@xxxxxxxxx, bhe@xxxxxxxxxx, andrii@xxxxxxxxxx, yoshfuji@xxxxxxxxxxxxxx, dsahern@xxxxxxxxxx, kuba@xxxxxxxxxx, pabeni@xxxxxxxxxx, perex@xxxxxxxx, tiwai@xxxxxxxx, haojian.zhuang@xxxxxxxxx, robert.jarzmik@xxxxxxx, linux-mm@xxxxxxxxx, linux-arm-kernel@xxxxxxxxxxxxxxxxxxx, linuxppc-dev@xxxxxxxxxxxxxxxx, x86@xxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, linux-graphics-maintainer@xxxxxxxxxx, linux-ia64@xxxxxxxxxxxxxxx, linux-arch@xxxxxxxxxxxxxxx, loongarch@xxxxxxxxxxxxxxx, kvm@xxxxxxxxxxxxxxx, linux-s390@xxxxxxxxxxxxxxx, linux-sgx@xxxxxxxxxxxxxxx, linux-um@xxxxxxxxxxxxxxxxxxx, linux-acpi@xxxxxxxxxxxxxxx, linux-crypto@xxxxxxxxxxxxxxx, nvdimm@xxxxxxxxxxxxxxx, dmaengine@xxxxxxxxxxxxxxx, amd-gfx@xxxxxxxxxxxxxxxxxxxxx, dri-devel@xxxxxxxxxxxxxxxxxxxxx, etnaviv@xxxxxxxxxxxxxxxxxxxxx, linux-samsung-soc@xxxxxxxxxxxxxxx, intel-gfx@xxxxxxxxxxxxxxxxxxxxx, linux-mediatek@xxxxxxxxxxxxxxxxxxx, linux-arm-msm@xxxxxxxxxxxxxxx, freedreno@xxxxxxxxxxxxxxxxxxxxx, linux-rockchip@xxxxxxxxxxxxxxxxxxx, linux-tegra@xxxxxxxxxxxxxxx, virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx, linux-stm32@xxxxxxxxxxxxxxxxxxxxxxxxxxxx, linux-rdma@xxxxxxxxxxxxxxx, linux-media@xxxxxxxxxxxxxxx, linux-accelerators@xxxxxxxxxxxxxxxx, sparclinux@xxxxxxxxxxxxxxx, linux-scsi@xxxxxxxxxxxxxxx, linux-staging@xxxxxxxxxxxxxxx, target-devel@xxxxxxxxxxxxxxx, linux-usb@xxxxxxxxxxxxxxx, netdev@xxxxxxxxxxxxxxx, linux-fbdev@xxxxxxxxxxxxxxx, linux-aio@xxxxxxxxx, linux-fsdevel@xxxxxxxxxxxxxxx, linux-erofs@xxxxxxxxxxxxxxxx, linux-ext4@xxxxxxxxxxxxxxx, devel@xxxxxxxxxxxxxxxxxx, kexec@xxxxxxxxxxxxxxxxxxx, linux-xfs@xxxxxxxxxxxxxxx, bpf@xxxxxxxxxxxxxxx, linux-perf-users@xxxxxxxxxxxxxxx, kasan-dev@xxxxxxxxxxxxxxxx, selinux@xxxxxxxxxxxxxxx, alsa-devel@xxxxxxxxxxxxxxxx, kernel-team@xxxxxxxxxxx
- Delivery-date: Thu, 26 Jan 2023 09:29:14 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On Wed, Jan 25, 2023 at 12:38:49AM -0800, Suren Baghdasaryan wrote:
> Replace indirect modifications to vma->vm_flags with calls to modifier
> functions to be able to track flag changes and to keep vma locking
> correctness. Add a BUG_ON check in ksm_madvise() to catch indirect
> vm_flags modification attempts.
>
> Signed-off-by: Suren Baghdasaryan <surenb@xxxxxxxxxx>
Acked-by: Mike Rapoport (IBM) <rppt@xxxxxxxxxx>
> ---
> arch/powerpc/kvm/book3s_hv_uvmem.c | 5 ++++-
> arch/s390/mm/gmap.c | 5 ++++-
> mm/khugepaged.c | 2 ++
> mm/ksm.c | 2 ++
> 4 files changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/arch/powerpc/kvm/book3s_hv_uvmem.c
> b/arch/powerpc/kvm/book3s_hv_uvmem.c
> index 1d67baa5557a..325a7a47d348 100644
> --- a/arch/powerpc/kvm/book3s_hv_uvmem.c
> +++ b/arch/powerpc/kvm/book3s_hv_uvmem.c
> @@ -393,6 +393,7 @@ static int kvmppc_memslot_page_merge(struct kvm *kvm,
> {
> unsigned long gfn = memslot->base_gfn;
> unsigned long end, start = gfn_to_hva(kvm, gfn);
> + unsigned long vm_flags;
> int ret = 0;
> struct vm_area_struct *vma;
> int merge_flag = (merge) ? MADV_MERGEABLE : MADV_UNMERGEABLE;
> @@ -409,12 +410,14 @@ static int kvmppc_memslot_page_merge(struct kvm *kvm,
> ret = H_STATE;
> break;
> }
> + vm_flags = vma->vm_flags;
> ret = ksm_madvise(vma, vma->vm_start, vma->vm_end,
> - merge_flag, &vma->vm_flags);
> + merge_flag, &vm_flags);
> if (ret) {
> ret = H_STATE;
> break;
> }
> + reset_vm_flags(vma, vm_flags);
> start = vma->vm_end;
> } while (end > vma->vm_end);
>
> diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c
> index 3a695b8a1e3c..d5eb47dcdacb 100644
> --- a/arch/s390/mm/gmap.c
> +++ b/arch/s390/mm/gmap.c
> @@ -2587,14 +2587,17 @@ int gmap_mark_unmergeable(void)
> {
> struct mm_struct *mm = current->mm;
> struct vm_area_struct *vma;
> + unsigned long vm_flags;
> int ret;
> VMA_ITERATOR(vmi, mm, 0);
>
> for_each_vma(vmi, vma) {
> + vm_flags = vma->vm_flags;
> ret = ksm_madvise(vma, vma->vm_start, vma->vm_end,
> - MADV_UNMERGEABLE, &vma->vm_flags);
> + MADV_UNMERGEABLE, &vm_flags);
> if (ret)
> return ret;
> + reset_vm_flags(vma, vm_flags);
> }
> mm->def_flags &= ~VM_MERGEABLE;
> return 0;
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index 8abc59345bf2..76b24cd0c179 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -354,6 +354,8 @@ struct attribute_group khugepaged_attr_group = {
> int hugepage_madvise(struct vm_area_struct *vma,
> unsigned long *vm_flags, int advice)
> {
> + /* vma->vm_flags can be changed only using modifier functions */
> + BUG_ON(vm_flags == &vma->vm_flags);
> switch (advice) {
> case MADV_HUGEPAGE:
> #ifdef CONFIG_S390
> diff --git a/mm/ksm.c b/mm/ksm.c
> index 04f1c8c2df11..992b2be9f5e6 100644
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -2573,6 +2573,8 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned
> long start,
> struct mm_struct *mm = vma->vm_mm;
> int err;
>
> + /* vma->vm_flags can be changed only using modifier functions */
> + BUG_ON(vm_flags == &vma->vm_flags);
> switch (advice) {
> case MADV_MERGEABLE:
> /*
> --
> 2.39.1
>
>
|