Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2640238lqp; Mon, 25 Mar 2024 05:24:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXa2ZOUxtkMJM5xAe7s+52FQ46O3f3b8KkRiOij20p/WBJr8eafbOnwqdF9egpEChnaXz/2soS3R2r71bOqFvYUVj1ucXLY76CxVUHdrQ== X-Google-Smtp-Source: AGHT+IF5blSiSPKrElhWrvcZLBB+F0PgnXyGvZvh3fmUM0kUQlVJ8cDP0tFTTWxCSMvxhORBIYey X-Received: by 2002:a05:622a:2d2:b0:431:3ec5:b21e with SMTP id a18-20020a05622a02d200b004313ec5b21emr8596233qtx.2.1711369457832; Mon, 25 Mar 2024 05:24:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711369457; cv=pass; d=google.com; s=arc-20160816; b=cIE1kyd+H0hlvmTktXcv2SbMgFmnOztlWYcm2PwMjcK2PfTcerf35yPJUixO/yuMWS DK69YW2ypduRjwYxBZWaFTPdSwZ2wLjgsgqlyJqNSH/EpT53kaPlwB3OAENQ1bYSjwr0 3Iim7f16apQX37O18pmD7fNp1EO+TYZ+doEFYaXSkQiPpJCa6AFTMVlsxRwc/qFlr/sD pUnyvk1vip7KDD94iTs0nEJ9JNq9LvMK14Z45jEgp+IR+7ajkU2YUb1TLqVOvbBZCVgp cLx0WIzCepjdt+y6xtJnvAyMktyYclWBAjM8yQBggorL92r2w7snDbrPKi3Ut6Bnz026 k0QA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:message-id:date:references:in-reply-to:subject:cc:to :from:dkim-signature; bh=bs/lt/DA2+wpHvLeIzYx+x5jXfiFwDnY+Te0VwQi8sg=; fh=YxGrYOEEffhqqyVNQ63PmTDMhXlfhrMehJnLsE5J0Ec=; b=iENd51XWN1WF9NQDiEkLA7JKLd/GKQ7qfKRPvb/kDEUKVHj3bQWTfUVig3QOryCsX/ 5WQhlZIoAcg58HnMMJiosnSHgm7FnW0zIMzbbVisUAAVWzt4b7COapwiIhhdke4jqre3 Pce+xO5VSTe/i/PgRuzFm9IRZk295ScpRaFoWSfbvOotGU2nRTJI8qUuSbhUkgSeP2ej P4/jbqUaF86G+gnuaUrbZ3qPMS/1ns+5zYyGAT2Pi/eOyhl7l6DwsfxI+T5cwA80er1T o21ZePT19bTFP/q3qIhYOd7AisQW4W74GRK9OldB2C6bAwRGTfZSBKMyKH9j5cRinlA8 H2Mw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SvhgNyGU; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-116452-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116452-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ge5-20020a05622a5c8500b004312359aa67si5186925qtb.409.2024.03.25.05.24.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 05:24:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116452-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SvhgNyGU; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-116452-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116452-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8716E1C35E74 for ; Mon, 25 Mar 2024 12:24:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 35EF7155A2B; Mon, 25 Mar 2024 07:31:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="SvhgNyGU" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85FBD13C68B for ; Mon, 25 Mar 2024 03:18:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711336729; cv=none; b=I8zMWpwHPJ5yvlooJBIFJDR/DX7nNEP2AXoE+FQz8F58K7jXvSWtx2GPOTbNNtTOp7yW6f/9A9JT9NPeiGmRqEg1ST7JDtiy+XKpApkaSY46bFZtLX/XyDEriSghooX6CDFHp4JgDEV0Y2hjmsuYhNxOBOcrZPIXl5ewrRjhsoA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711336729; c=relaxed/simple; bh=WvY/llrOOyyGpZRAhKAzslr8m+fAoMpt2YTsv1kupJQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=MK2F4rPdhFqic9ICIZAGj7q/Iv9X7fm1uYcorAMrAxpkCFAkoTB/uLfhppWmG3FlBJE8AF5jY5aO5G3cLII4L00b8TPrC74mpgz2gxb7FEAL7xPFSoCPUjAVD1B/VN+JyoGx7sbYNnj/k43D3npGCkL0EWn42IXuqjFLDGipp4I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=SvhgNyGU; arc=none smtp.client-ip=198.175.65.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711336728; x=1742872728; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=WvY/llrOOyyGpZRAhKAzslr8m+fAoMpt2YTsv1kupJQ=; b=SvhgNyGUE1mrAHQdOXI/FSN99fz6u4y1bIoIZowf4IDsDLmWJBy164ga r2SqLzIEMdNff+Mul73XcZjC1c2jMTpCl5bsoMYrqj0Xj4LfTjg5EQlyL 558ww55JO2K6PpW3KoJHSNhGQy8VHhYoIWfrO6hG9ha/IYbMc8TMfA7fE uU0QQZrpzGrbV3rU+EgR+FLT6xSfsPXwJl8EQCbSnv5Nd+PF/YFPTbkqr oj4QNzIbaor5/zWS8YNj+P08Tf6ExucL23Q2eWdBsqAlGfwL3VS+rNABo MbL9+VaVC7V8ndY8w4IsFo+XX2jKooQkrjO3QKoHoa8w+SAdJKarkoEWu Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="6427282" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="6427282" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2024 20:18:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="46606514" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2024 20:18:45 -0700 From: "Huang, Ying" To: "Paul E. McKenney" Cc: Akira Yokosawa , linux-kernel@vger.kernel.org, linux-mm@kvack.org, ryan.roberts@arm.com, chrisl@kernel.org Subject: Re: Can you help us on memory barrier usage? (was Re: [PATCH v4 4/6] mm: swap: Allow storage of all mTHP orders) In-Reply-To: <766cfb68-f82a-4163-9dc1-5f4483fa5a7a@paulmck-laptop> (Paul E. McKenney's message of "Sun, 24 Mar 2024 17:01:36 -0700") References: <87r0g3q9cz.fsf_-_@yhuang6-desk2.ccr.corp.intel.com> <766cfb68-f82a-4163-9dc1-5f4483fa5a7a@paulmck-laptop> Date: Mon, 25 Mar 2024 11:16:51 +0800 Message-ID: <87r0fzova4.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ascii "Paul E. McKenney" writes: > On Sat, Mar 23, 2024 at 11:11:09AM +0900, Akira Yokosawa wrote: >> [Use Paul's reachable address in CC; >> trimmed CC list, keeping only those who have responded so far.] >> >> Hello Huang, >> Let me chime in. >> >> On Fri, 22 Mar 2024 06:19:52 -0700, Huang, Ying wrote: >> > Hi, Paul, >> > >> > Can you help us on WRITE_ONCE()/READ_ONCE()/barrier() usage as follows? >> > For some example kernel code as follows, >> > >> > " >> > unsigned char x[16]; >> > >> > void writer(void) >> > { >> > memset(x, 1, sizeof(x)); >> > /* To make memset() take effect ASAP */ >> > barrier(); >> > } >> > >> > unsigned char reader(int n) >> > { >> > return READ_ONCE(x[n]); >> > } >> > " >> > >> > where, writer() and reader() may be called on 2 CPUs without any lock. >> > It's acceptable for reader() to read the written value a little later. > > What are your consistency requirements? For but one example, if reader(3) > gives the new value, is it OK for a later call to reader(2) to give the > old value? writer() will be called with a lock held (sorry, my previous words aren't correct here). After the racy checking in reader(), we will acquire the lock and check "x[n]" again to confirm. And, there are no dependencies between different "n". All in all, we can accept almost all races between writer() and reader(). My question is, if there are some operations between writer() and unlocking in its caller, whether does barrier() in writer() make any sense? Make write instructions appear a little earlier in compiled code? Mark the memory may be read racy? Or doesn't make sense at all? > Until we know what your requirements are, it is hard to say whether the > above code meets those requirements. In the meantime, I can imagine > requirements that it meets and others that it does not. > > Also, Akira's points below are quite important. Replied for his email. -- Best Regards, Huang, Ying