Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp9948rdb; Wed, 18 Oct 2023 16:07:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEP/gSXX+RAUVQKaLQTplv307W7MO3yQG8vcywkSo7OEBrhIGZ7wcb9ykHBHlHtS53Az7rl X-Received: by 2002:a05:6359:660a:b0:166:dfcb:d712 with SMTP id sm10-20020a056359660a00b00166dfcbd712mr378409rwb.10.1697670437743; Wed, 18 Oct 2023 16:07:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697670437; cv=none; d=google.com; s=arc-20160816; b=YZ4KXPpCg1PSdBc4nVFeT397wf5kOV02fYAFyfxVkjf6kwfR9mqPj2fp2lldMxnPv3 y8nvJ6spLQ7D9dApWiIM3iLRzyOptzsTtYl5kk2+OJpG2GWSgfRJj08nbkZ4F+9iN2tG 7i+KEN2KqJgqbOiS8dPCvE4jnataQPXf+8CYnWroneIBQQ4cegfH/7W4yBmgntyNBdgS AHzMte8AnUpDpSko0CF8lsloap2AOFLY2v86Z9XEUEgapfgHjhZ5JRp304jWjmfLdMVm 44T1t2Tm5Zd4sNeLep+CWDHOw8EX1rMF3i7cWMDewSKJN1gukFcAeRyMpIIsi0Z6Innc HJUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=LvRlSdXve8vHq+1t3BIUEFBdp86rzaUM1bfVMcoReYE=; fh=yYaFxW14JnU5qZhSrZaVX0Gi5mVUwcKo866zJECR4bA=; b=FS3STFhDle2uPG4xemYW9+tCCv3CzDVEnc2JgQXVFKxiO9d2qWTmvkxflqG791wGNZ Ih1wpodCsJk9huyK7CCVnIF3B2zjcgXJTXoc+6xZhdhp5Qdw67jzZB25ounYZpuVJ12A F1Bfk1DRN6NejIDd0hQLRNWKigCCtRJ83vxGYlHR3jxnELUFnv2nnv+jjOMlg8jzXoxN IAvqcPQZ/SOtu+x7QPLggX5nvS1CtxJrfMcfRJieRpqtaJFUH7lNY3BA/4AIWHipenba uOuljutgWPnSKZLije3Of2Aa/qLChRVJjh4J7j1+GW/XDiUV5UdLaFg40x68cdAI4L2M kJ2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=a5dyPq1s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id g18-20020a056a001a1200b00690f9ca0f99si2844510pfv.12.2023.10.18.16.07.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:07:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=a5dyPq1s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 0CAF2802887A; Wed, 18 Oct 2023 16:07:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231812AbjJRXHF (ORCPT + 99 others); Wed, 18 Oct 2023 19:07:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjJRXHE (ORCPT ); Wed, 18 Oct 2023 19:07:04 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5EF4116 for ; Wed, 18 Oct 2023 16:07:01 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-5079fa1bbf8so7287056e87.0 for ; Wed, 18 Oct 2023 16:07:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1697670420; x=1698275220; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=LvRlSdXve8vHq+1t3BIUEFBdp86rzaUM1bfVMcoReYE=; b=a5dyPq1s7GNxdiNmv/46Cix5pr+qzZtX20NhNq/xMNHgSYMLl3w+Eb9o9BCKRpe92/ cJApv7O15B4Dl2NT7HxYTrYdAs5Sqx5DZBrDFoSOQrbvaQJS2SxVHpfRjKnq0LtYBBlX +mpTI+otJaKYrIoi+tWL2ydsyCZ8UfvuYN7hw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697670420; x=1698275220; h=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=LvRlSdXve8vHq+1t3BIUEFBdp86rzaUM1bfVMcoReYE=; b=CtbAQsLRaCgNYuB4dTGr7yiHKiTPvY+8bqG2Yykcy+pj773XufFAZveX/pAAE0hg4t LNIYfdk+GtJAtbvH/2AZJgfEblI+ksmCDw1gkL6aqPrGCR2wVleDOyhR501sjxivxNPE kuFypOaZV9ztQVSWehc2J743mRuxRRQ1whvaZuwFcwx3SHtWU1v8JLSi2ReZVVulmbNc qLPYQuPbShPLXEysxODFj7DWKzlhzt1ULrN4JBCcajP/aPcpx9TILh+nhh87CjVvAPOD NW53xjr8untCCUIFaz8kILKsc16KQM74FnHm42Rx+PHNwgpE36927gCO8fCsPdDRBdv0 mi9A== X-Gm-Message-State: AOJu0YzHpFMpXUgAtTXan4immxR3eAnMxPC2omZhUJDMrO5qFDYOTEbA 0Lhi/gQLsDTIAoMK3AhZAjNYMBELKp9p0OIozHB3e/Yq X-Received: by 2002:ac2:5472:0:b0:503:264b:efc9 with SMTP id e18-20020ac25472000000b00503264befc9mr269931lfn.18.1697670420009; Wed, 18 Oct 2023 16:07:00 -0700 (PDT) Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com. [209.85.208.47]) by smtp.gmail.com with ESMTPSA id b42-20020a509f2d000000b0053e43492ef1sm3543495edf.65.2023.10.18.16.06.59 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Oct 2023 16:06:59 -0700 (PDT) Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-533d31a8523so12446234a12.1 for ; Wed, 18 Oct 2023 16:06:59 -0700 (PDT) X-Received: by 2002:a17:907:3f04:b0:9be:77cd:4c2c with SMTP id hq4-20020a1709073f0400b009be77cd4c2cmr451577ejc.28.1697670418807; Wed, 18 Oct 2023 16:06:58 -0700 (PDT) MIME-Version: 1.0 References: <20231010164234.140750-1-ubizjak@gmail.com> <0617BB2F-D08F-410F-A6EE-4135BB03863C@vmware.com> <7D77A452-E61E-4B8B-B49C-949E1C8E257C@vmware.com> <9F926586-20D9-4979-AB7A-71124BBAABD3@vmware.com> <3F9D776E-AD7E-4814-9E3C-508550AD9287@vmware.com> <28B9471C-4FB0-4AB0-81DD-4885C3645E95@vmware.com> In-Reply-To: From: Linus Torvalds Date: Wed, 18 Oct 2023 16:06:40 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 -tip] x86/percpu: Use C for arch_raw_cpu_ptr() To: Uros Bizjak , peterz@infradead.org Cc: Nadav Amit , "the arch/x86 maintainers" , Linux Kernel Mailing List , Andy Lutomirski , Brian Gerst , Denys Vlasenko , "H . Peter Anvin" , Thomas Gleixner , Josh Poimboeuf , Nick Desaulniers Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 18 Oct 2023 16:07:15 -0700 (PDT) On Wed, 18 Oct 2023 at 15:40, Linus Torvalds wrote: > > See for example __count_vm_event() vs count_vm_event(). > > In fact, that particular use isn't even in an interrupt-safe context, > that's an example of literally "I'd rather be fast that correct for > certain statistics that aren't all that important". .. just to clarify - I don't think the VM statistics code isn't even updated from interrupts, but it is still incorrect to do "raw_cpu_add()" even in just process context, because on architectures where it results in separate load-op-store instructions, you can get preempted in the middle, and now your loaded value is some old stale one. So when you get back, somebody else might have updated the count, but you'll still end up doing the store using the stale value. For VM statistics like the BALLOON_MIGRATE, nobody cares. The stats may be incorrect, but they aren't a correctness issue, and they'll be in the right ballpark because the race is not generally hit. So "interrupt safe" here is not necessarily about actual interrupts themselves directly. You *can* have that too, but it can also be about just an interrupt causing preemption. Anyway, again, none of this is relevant on x86, since the single-instruction rmw percpu sequence is obviously non-interruptible, The one oddity on x86 is that because 'xchg' always has an implied lock, so there we *do* have a multi-instruction sequence. And then - and *ONLY* then - the raw-vs-this matters even on x86: "raw" just does a "load-store" pair, while "this" does a cmpxchg loop (the latter of which is safe for both irq use and preemption because the cmpxchg obviously re-checks the original value). But even in that xchg case, the "volatile" part of the asm is a complete red herring and shouldn't exist. Linus