Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp21942653rwd; Fri, 30 Jun 2023 01:36:32 -0700 (PDT) X-Google-Smtp-Source: APBJJlF/s1+Jf6NXTLDwTMBccTf+o1gibfhoTIKWhh0lKN8AmwiXsn7VmhQty9cykRQQKrKZ1wE8 X-Received: by 2002:aa7:9f09:0:b0:682:562a:39ae with SMTP id g9-20020aa79f09000000b00682562a39aemr1931003pfr.32.1688114191868; Fri, 30 Jun 2023 01:36:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688114191; cv=none; d=google.com; s=arc-20160816; b=ELKWAGUA2cO89jwVGbsfT/vksv7ee/w/TND4OQWQ8XySizgvAksSy5ABd73IupkIa5 Jgu71wIUbwigX/mUKZ6Il0AmH0DSGxyWjhSgwtwCSQgktmzoHC5tdVyQ5MMWd9CYr8jA Zni1dKiOyXOMeJmR1iVHkEDJ5Uxm/IHRF2UpefUqY67Pr+kAFJq6Wu/Fc0C/3bHDu657 IvlM4hk4LVd2iC51yySlCt6db/o/kdKpxlB1jEST13NbLUjMOsyvdCKIVXgCfX1Yvktf Sod64JeBUKhvRcwMjNTEp1NXzP+8t0bW1RMVHmhvhkTzMfdEiYiAEZBbtaSa2YKexkxM RlXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :references:cc:to:from:content-language:user-agent:mime-version:date :message-id; bh=cRYyHPJ0l3JptHpg3mFpGfjchjllb0zu8LBlb7XT5hw=; fh=ivuWAjqot7/dbPl/YcqDbDqT2IvntrDvmLIsn/3rmDk=; b=RKIZDp7ipoaHfCdW80MzN6R7biIO0JBilSvO/S3lC7PC1jBWWEZ36XLwAmBB3eC4KQ V1yj4QnhKM4+LKE/OBL7OXB0wNYvTBhzCPGVjJM+TYgOE/6peoBUYImqMk9radhLF3XY KePf6rWSZ1XLW3hKOPVYksYqf84ilCHaJ5GQEHM41pk6s+SU96LO6n45WWSCW/JKj/Rp cpRV57u43GUbD/+/CtB9LzaTiGi2rtc0YkEfLceIx7nFu4Ny2ZDFhRGLnoDtfIvEjNVl ua0X7lDZsfOhJtaK7p38uGSH8Cca4GVkjN84LCTFwUT3C8eWMOsriB6kV+raFg2cJiP/ Ckew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k26-20020a635a5a000000b005534371608dsi12117095pgm.849.2023.06.30.01.36.17; Fri, 30 Jun 2023 01:36:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232437AbjF3I2Y (ORCPT + 99 others); Fri, 30 Jun 2023 04:28:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232488AbjF3I2M (ORCPT ); Fri, 30 Jun 2023 04:28:12 -0400 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51A09130 for ; Fri, 30 Jun 2023 01:28:10 -0700 (PDT) Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-3fbc244d386so10538685e9.2 for ; Fri, 30 Jun 2023 01:28:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688113689; x=1690705689; h=content-transfer-encoding:in-reply-to:subject:references:cc:to:from :content-language:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cRYyHPJ0l3JptHpg3mFpGfjchjllb0zu8LBlb7XT5hw=; b=YYSZBPBPXocoJkB+iGgFMsY7QZQCsmg0rw7EIm1Nhl9uPPmli4mcNlrkS56IT9M8yN s/URALz1dz6U4ZRuKK2cb/IQHIZlAed/1SG3FklezcCMoQ07WCYGZ2JpUb/oIU0dirk1 TCEhO9X6ZC/SfrohLHn4z8MCkfT7dZdutqbAbD31ZHV1vw0M/SkKyeYNq4iF/4+YGUUA sTQdgKCpCoUtIzdNLNE5kVtBTxGHEeFwLisGfVyDQNf2J5GdzJo3OQmPOeyXLt9LHAz7 QhjFbSUnlipjpFBNAi2IRJ8uk+hV/tLj4OcFAoTv3HzSjo9GCmp+yjeHv/x5IFhZ/Atz kvXA== X-Gm-Message-State: AC+VfDwbEgMvNIa5AY+hARMRVJ4nYRcDoqEK7kE/HyLIe7XO1x7isxSb nK+oZRo2kF55/aeFq+QWBM0= X-Received: by 2002:a7b:cb88:0:b0:3fb:b890:128e with SMTP id m8-20020a7bcb88000000b003fbb890128emr1255564wmi.33.1688113688346; Fri, 30 Jun 2023 01:28:08 -0700 (PDT) Received: from ?IPV6:2a0b:e7c0:0:107::aaaa:59? ([2a0b:e7c0:0:107::aaaa:59]) by smtp.gmail.com with ESMTPSA id o23-20020a05600c379700b003fae92e7a8dsm12201517wmr.27.2023.06.30.01.28.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 30 Jun 2023 01:28:07 -0700 (PDT) Message-ID: Date: Fri, 30 Jun 2023 10:28:05 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Content-Language: en-US From: Jiri Slaby To: Suren Baghdasaryan Cc: akpm@linux-foundation.org, michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, ldufour@linux.ibm.com, paulmck@kernel.org, mingo@redhat.com, will@kernel.org, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, kent.overstreet@linux.dev, punit.agrawal@bytedance.com, lstoakes@gmail.com, peterjung1337@gmail.com, rientjes@google.com, chriscli@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, rppt@kernel.org, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, leewalsh@google.com, posk@google.com, michalechner92@googlemail.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com References: <20230227173632.3292573-1-surenb@google.com> <20230227173632.3292573-30-surenb@google.com> <9a8d788c-b8ba-1b8a-fd79-0e25b1b60bed@kernel.org> Subject: Re: [PATCH v4 29/33] x86/mm: try VMA lock-based page fault handling first In-Reply-To: <9a8d788c-b8ba-1b8a-fd79-0e25b1b60bed@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 30. 06. 23, 8:35, Jiri Slaby wrote: > On 29. 06. 23, 17:30, Suren Baghdasaryan wrote: >> On Thu, Jun 29, 2023 at 7:40 AM Jiri Slaby wrote: >>> >>> Hi, >>> >>> On 27. 02. 23, 18:36, Suren Baghdasaryan wrote: >>>> Attempt VMA lock-based page fault handling first, and fall back to the >>>> existing mmap_lock-based handling if that fails. >>>> >>>> Signed-off-by: Suren Baghdasaryan >>>> --- >>>>    arch/x86/Kconfig    |  1 + >>>>    arch/x86/mm/fault.c | 36 ++++++++++++++++++++++++++++++++++++ >>>>    2 files changed, 37 insertions(+) >>>> >>>> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig >>>> index a825bf031f49..df21fba77db1 100644 >>>> --- a/arch/x86/Kconfig >>>> +++ b/arch/x86/Kconfig >>>> @@ -27,6 +27,7 @@ config X86_64 >>>>        # Options that are inherently 64-bit kernel only: >>>>        select ARCH_HAS_GIGANTIC_PAGE >>>>        select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 >>>> +     select ARCH_SUPPORTS_PER_VMA_LOCK >>>>        select ARCH_USE_CMPXCHG_LOCKREF >>>>        select HAVE_ARCH_SOFT_DIRTY >>>>        select MODULES_USE_ELF_RELA >>>> diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c >>>> index a498ae1fbe66..e4399983c50c 100644 >>>> --- a/arch/x86/mm/fault.c >>>> +++ b/arch/x86/mm/fault.c >>>> @@ -19,6 +19,7 @@ >>>>    #include           /* >>>> faulthandler_disabled()      */ >>>>    #include                       /* >>>> efi_crash_gracefully_on_page_fault()*/ >>>>    #include >>>> +#include                         /* find_and_lock_vma() */ >>>> >>>>    #include          /* boot_cpu_has, >>>> ...            */ >>>>    #include                       /* dotraplinkage, >>>> ...           */ >>>> @@ -1333,6 +1334,38 @@ void do_user_addr_fault(struct pt_regs *regs, >>>>        } >>>>    #endif >>>> >>>> +#ifdef CONFIG_PER_VMA_LOCK >>>> +     if (!(flags & FAULT_FLAG_USER)) >>>> +             goto lock_mmap; >>>> + >>>> +     vma = lock_vma_under_rcu(mm, address); >>>> +     if (!vma) >>>> +             goto lock_mmap; >>>> + >>>> +     if (unlikely(access_error(error_code, vma))) { >>>> +             vma_end_read(vma); >>>> +             goto lock_mmap; >>>> +     } >>>> +     fault = handle_mm_fault(vma, address, flags | >>>> FAULT_FLAG_VMA_LOCK, regs); >>>> +     vma_end_read(vma); >>>> + >>>> +     if (!(fault & VM_FAULT_RETRY)) { >>>> +             count_vm_vma_lock_event(VMA_LOCK_SUCCESS); >>>> +             goto done; >>>> +     } >>>> +     count_vm_vma_lock_event(VMA_LOCK_RETRY); >>> >>> This is apparently not strong enough as it causes go build failures >>> like: >>> >>> [  409s] strconv >>> [  409s] releasep: m=0x579e2000 m->p=0x5781c600 p->m=0x0 p->status=2 >>> [  409s] fatal error: releasep: invalid p state >>> [  409s] >>> >>> [  325s] hash/adler32 >>> [  325s] hash/crc32 >>> [  325s] cmd/internal/codesign >>> [  336s] fatal error: runtime: out of memory >> >> Hi Jiri, >> Thanks for reporting! I'm not familiar with go builds. Could you >> please explain the error to me or point me to some documentation to >> decipher that error? > > Sorry, we are on the same boat -- me neither. It only popped up in our > (openSUSE) build system and I only tracked it down by bisection. Let me > know if I can try something (like a patch or gathering some debug info). FWIW, a failed build log: https://decibel.fi.muni.cz/~xslaby/n/vma/log.txt and a strace for it: https://decibel.fi.muni.cz/~xslaby/n/vma/strace.txt An excerpt from the log: [ 55s] runtime: marked free object in span 0x7fca6824bec8, elemsize=192 freeindex=0 (bad use of unsafe.Pointer? try -d=checkptr) [ 55s] 0xc0002f2000 alloc marked [ 55s] 0xc0002f20c0 alloc marked [ 55s] 0xc0002f2180 alloc marked [ 55s] 0xc0002f2240 free unmarked [ 55s] 0xc0002f2300 alloc marked [ 55s] 0xc0002f23c0 alloc marked [ 55s] 0xc0002f2480 alloc marked [ 55s] 0xc0002f2540 alloc marked [ 55s] 0xc0002f2600 alloc marked [ 55s] 0xc0002f26c0 alloc marked [ 55s] 0xc0002f2780 alloc marked [ 55s] 0xc0002f2840 alloc marked [ 55s] 0xc0002f2900 alloc marked [ 55s] 0xc0002f29c0 free unmarked [ 55s] 0xc0002f2a80 alloc marked [ 55s] 0xc0002f2b40 alloc marked [ 55s] 0xc0002f2c00 alloc marked [ 55s] 0xc0002f2cc0 alloc marked [ 55s] 0xc0002f2d80 alloc marked [ 55s] 0xc0002f2e40 alloc marked [ 55s] 0xc0002f2f00 alloc marked [ 55s] 0xc0002f2fc0 alloc marked [ 55s] 0xc0002f3080 alloc marked [ 55s] 0xc0002f3140 alloc marked [ 55s] 0xc0002f3200 alloc marked [ 55s] 0xc0002f32c0 alloc marked [ 55s] 0xc0002f3380 free unmarked [ 55s] 0xc0002f3440 free marked zombie An excerpt from strace: > 2348 clone3({flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, child_tid=0x7fcaa6a1b990, parent_tid=0x7fcaa6a1b990, exit_signal=0, stack=0x7fcaa621b000, stack_size=0x7ffe00, tls=0x7fcaa6a1b6c0} => {parent_tid=[2350]}, 88) = 2350 > 2348 clone3({flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, child_tid=0x7fcaa5882990, parent_tid=0x7fcaa5882990, exit_signal=0, stack=0x7fcaa5082000, stack_size=0x7ffe00, tls=0x7fcaa58826c0} => {parent_tid=[2351]}, 88) = 2351 > 2350 <... clone3 resumed> => {parent_tid=[2372]}, 88) = 2372 > 2351 <... clone3 resumed> => {parent_tid=[2354]}, 88) = 2354 > 2351 <... clone3 resumed> => {parent_tid=[2357]}, 88) = 2357 > 2354 <... clone3 resumed> => {parent_tid=[2355]}, 88) = 2355 > 2355 <... clone3 resumed> => {parent_tid=[2370]}, 88) = 2370 > 2370 mmap(NULL, 262144, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0 > 2370 <... mmap resumed>) = 0x7fca68249000 > 2372 <... clone3 resumed> => {parent_tid=[2384]}, 88) = 2384 > 2384 <... clone3 resumed> => {parent_tid=[2388]}, 88) = 2388 > 2388 <... clone3 resumed> => {parent_tid=[2392]}, 88) = 2392 > 2392 <... clone3 resumed> => {parent_tid=[2395]}, 88) = 2395 > 2395 write(2, "runtime: marked free object in s"..., 36 I.e. IIUC, all are threads (CLONE_VM) and thread 2370 mapped ANON 0x7fca68249000 - 0x7fca6827ffff and go in thread 2395 thinks for some reason 0x7fca6824bec8 in that region is "bad". > thanks,-- -- js suse labs