Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2764151rwd; Mon, 15 May 2023 17:00:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ50E5ChXruviFujUEgr+Muz6i3wyX13bmNJJnyJ7TOCdpY5fzJmRO6JIHuPZHGEEb/fk10C X-Received: by 2002:a05:6a21:3399:b0:e9:5b0a:deff with SMTP id yy25-20020a056a21339900b000e95b0adeffmr45861695pzb.22.1684195230631; Mon, 15 May 2023 17:00:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684195230; cv=none; d=google.com; s=arc-20160816; b=C9Y0cHnQ2AjZ6V1iUGSo+fKImXsxPryjQ+n8S3DpUG7VwrKYmazBSVdK7SmPkQjR2Z TDNpo9PrGvr4AZPuuVydZW5S/DADX1o8say7Rj2MYA8jZAsEX2dsvoeRYs8MP9T7EMeN 8oZ8LKiGXcOU5xbsyDOotaihr+qayDcV590z0N6ln4Jv6nuVQviBfw24ic9KYyINd0FX cNnNnXWbKaBoklXav/hb/OyN+s9WfyBkCBgVZlwd393UrhEfNhKVAWY23M7NSW+sFm7w gLjx+Q9YdjhFqmn6Nrca9lxb+iK6M9r0vFUD9nMTcOlSviIcwhbHJMVdlMl1O86Rqk7k vmpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=kKOCYYZhrcXCBpj5u3tDd9MBX2qjyYOiEFbdtJlTHzY=; b=okDGTSHZ8EVUbUV8uX/gLvKRDtFTbG26AaK/anFXYwrYOxaB9ywQItDkIdIE6o85Ty fW5M2SgoYD7xKISyxMfAIM8N7/u/44ux/FI2l5l3b/6RMMngvHc8xJcoj6DYHl5nfi4u r1xq7CkvzD1UaEIq21fdUEB0Lf3MwF6a0qdtjgSz2AUCMYFHCA9nnS5IbK0uru+L/yHf kb0XiBjZSgWNCYomGVVa6bAYGBefCypMPWKlt/C19gGf11G8w5QOMMpzTLaZRXXZVjQP qAYSax6jS+3e7xcHEp2bAqp+an/e3N8qKmEf1zy5dyhvxr2/b8K5MJnpB1dYwq40PzxP YAAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=Tm54eW2K; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v17-20020a63b951000000b005342966f497si2150224pgo.712.2023.05.15.16.59.40; Mon, 15 May 2023 17:00:30 -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; dkim=pass header.i=@linux-foundation.org header.s=google header.b=Tm54eW2K; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245310AbjEOXDP (ORCPT + 99 others); Mon, 15 May 2023 19:03:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243628AbjEOXDO (ORCPT ); Mon, 15 May 2023 19:03:14 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE125185 for ; Mon, 15 May 2023 16:03:12 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-96aa0cab88dso691640766b.1 for ; Mon, 15 May 2023 16:03:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1684191791; x=1686783791; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=kKOCYYZhrcXCBpj5u3tDd9MBX2qjyYOiEFbdtJlTHzY=; b=Tm54eW2KsZuCP8z16TJjmAI0Zg/rdQzWno0YhfnIWovY6jQ1nCcZpEou7AKTBey6FW 7CRi1QTifEVMD9Z3zgB21RKKbyG5voar0+aQP7lIP5W9HGQg7Cb+z+DequkAfaOif44d sMwbuYmc5cR7PuecUnkswHIJl/VJioebIBo2Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684191791; x=1686783791; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kKOCYYZhrcXCBpj5u3tDd9MBX2qjyYOiEFbdtJlTHzY=; b=jmpoALnEfDVwO/2Oc/krmT1Z5TR8My6k0Kbe3uhKOu5fHex0zqo20B2WvC2Xp5vY9F aYsApIzOnghzpja3g+R+g2kaTh+Bi4fiFO/7nv8fkeGTlhHslf/DaXIQ84SkrDfPtulU 3WKL33oNgyRJcds7jEy5VaIEOEX9yCYBMZ6JzBJuzuEBJ6TTR+HBGyV7PfO+g48lPPSY JhNte/NgNbz5MPQoFSfMWvPL+3tJrO48SzcC8M9vxuwnKgeiPwjTaUxn3oTbjtpMwj1g 1mUlY7LiGGcoclKrxM8zAp5C+xvzCSRORiN0A2p+TlruH7JASh7vJuszb92d9ujia4Tf BN+Q== X-Gm-Message-State: AC+VfDxRJIrkOkq3M5g1oIRTl6eMeYgu6MVdGKq2CJMH00Pl9VnJtoIJ dKKQ6ApZS79bzVJQsuCX399bSwWbQvn4oMlaQisDvgBZ X-Received: by 2002:a17:906:ee86:b0:962:46d7:c8fc with SMTP id wt6-20020a170906ee8600b0096246d7c8fcmr35038699ejb.21.1684191791066; Mon, 15 May 2023 16:03:11 -0700 (PDT) Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com. [209.85.208.54]) by smtp.gmail.com with ESMTPSA id f7-20020a170906494700b00965bf86c00asm10342426ejt.143.2023.05.15.16.03.10 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 15 May 2023 16:03:10 -0700 (PDT) Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-50bd875398dso20150903a12.1 for ; Mon, 15 May 2023 16:03:10 -0700 (PDT) X-Received: by 2002:a17:907:36cb:b0:961:272d:bdb9 with SMTP id bj11-20020a17090736cb00b00961272dbdb9mr36642667ejc.43.1684191790244; Mon, 15 May 2023 16:03:10 -0700 (PDT) MIME-Version: 1.0 References: <20230424212130.590684-1-dave.hansen@linux.intel.com> <4433c3595db23f7c779b69b222958151b69ddd70.camel@intel.com> <148b3edb-b056-11a0-1684-6273a4a2d39a@intel.com> <4171c4b0-e24b-a7e2-9928-030cc14f1d8d@intel.com> <95c2e669-bce9-3dd5-e197-3faf816c4b45@intel.com> <93ae88a4-1dac-77bf-37f6-f8708a6d83b7@intel.com> In-Reply-To: From: Linus Torvalds Date: Mon, 15 May 2023 16:02:52 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [GIT PULL] x86/shstk for 6.4 To: Dave Hansen Cc: "Edgecombe, Rick P" , "dave.hansen@linux.intel.com" , "keescook@chromium.org" , "linux-kernel@vger.kernel.org" , "x86@kernel.org" , "akpm@linux-foundation.org" , Peter Zijlstra Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Mon, May 15, 2023 at 3:40=E2=80=AFPM Linus Torvalds wrote: > > mutex_lock(&mm->fork_lock); > if (atomic_read(&mm->mm_users) > 1 || > atomic_read(&mm->mm_count) > 1) { Again, just to clarify: at this point the mm_users/count checks are purely a heuristic. If they are both 1, then we know we're *currently* the only user, and the fork_lock means that no new users that matter can come in. If we race with things like /proc accesses that have raised either of those counts, and we happen to say "ok, we're not alone in the universe", then that just means that we fall back to the slow thread-safe path. Unfortunate, but not a huge deal. The slow path is what we do right now, and while it might be a bit slower with a 'lock cmpxchg' instead of a 'lock andb', it shouldn't be some *insanely* much slower case. So what we really want to do here is an optimistic and cheap "can we do the fast case" for the presumably common situation where we're really just a bog-standard single-threaded fork. IOW, the mm counts aren't somehow semantically important, we're literally just looking for a cheap test for a common case. That's my argument, at least. There may be flaws in that argument, like some memory ordering with some exit() case that decrements mm_users, but those should very much happen only after the exit() has already stopped using the page tables, so I don't think those can actually matter. Keyword here being "I don't think". Linus