From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53A1B1C862E for ; Sat, 27 Dec 2025 18:06:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766858770; cv=none; b=n8UtPMzHhSCEN4MBxVqAaJG1I0VGm9dgzB4bwhFcWH/5BpQ1BpBMFzADVCi5oD1WPSyds2OKJ9UVBp5MH1JkGeUVNULaWqGueHZqQXIBL7w/g373VROiWcgaYiby57aR1gX/47E1O/DS6q3wxoXymagv7/+Igyc0BixwRmnMjeY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766858770; c=relaxed/simple; bh=LeUb9b87hO3JYnam6vyZxs7ADNv5kA5A/VeH/0XCy50=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CVVep/QpYF4Ot17y6y2IMtPhLle9QdYmvXgz7KlQCAsmtK+dmQipcq9Zgke9Nje5t29dGdqKpM8yrbzRREfHNCuoU0IfK2Q8iNtVCtCzTHyrG2rfCgS8WWk4A2KoFCf9jSDYmpM6rh19vvlOT3aknRQARrWIJLPtx3jgfLuvNeI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=Da8tNiIu; arc=none smtp.client-ip=209.85.208.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Da8tNiIu" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-64dfb22c7e4so3574502a12.1 for ; Sat, 27 Dec 2025 10:06:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1766858767; x=1767463567; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=JrCO1sgoIm4eBTYLvvypdWXDZ87M9Cpcmd2K9vmntjw=; b=Da8tNiIuIRS6Nvxck8wyqahkHqhKg+rCg0xGpam59kaMwdOS2fbouIerSbAYgZJqwz LN0NwcRX2m3arnOB/BAOu9bOn28NL5l3dzcuR1Js8HlnVPuWFFUUkLxBI6tG1tix1hFf bfpmNcS5/rBbwnXWpFlfXFc0uNRVeuqrwe1Sc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766858767; x=1767463567; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JrCO1sgoIm4eBTYLvvypdWXDZ87M9Cpcmd2K9vmntjw=; b=xITOHh9GwyNLWxc9hXscqjvK+8cZg4//NM4auiwr13TL3RPY8+zJm2JmQU6ip05lZS JaJ4roCDIIzKLKgO0zfmc93eZjEK0Sha6IlzQQlxklA3yzOFKbQgNMhXnmeHi7L9YEOr 9k9HLqGK7/xrYZWK8jVg8Acvf/7hq5QGxo04ZEi640Po1LCtf1hzNtzAs3fgX3XPR55P KfHp95taqtWLiUWPxonebyE2p3SvtgoNyOXHYJuVN2XTK45gsaSjzgUBtGQT54qxKEgT W/JN0tyB3L4CkZOcE1sRmqgoZWrXDsAzrO6K5jz+3tVoXN+rCXz8Rirb6a/o4icKGCaX 6QGA== X-Forwarded-Encrypted: i=1; AJvYcCWS/mPMeY94p2nSdvk5CfSXMV/n4vXv/cFhsCZVuGdvFfPdKX0X7sf5YQpbKYoh/BjqSIRxoppRu4+ABXw=@vger.kernel.org X-Gm-Message-State: AOJu0YwUnw14QwfSr+uxVDjM3aeTYUY4HUoRhd6/A5idXDGVtTE+0NsD FpDy30vW0s8JEeCkpXqf4w9aY4jBOGwJ14W5p96ZqgpcwR6T/5sBaLatJPnhum2UCg== X-Gm-Gg: AY/fxX5JRsCzYLhZtnglzv/AV7fZ4cvWr/Q7l6cBhiLU/g1/8H9kKQTGn4lO9yXIHKP qB/m4RGtv+F0EjQskj7cNNfOq3qMG652Lp1DwdL9mP5Tv3Gyjl9lH+epYuObW5VfS6j2b6qdimy MA5t9nYyQ0xMt2tXCyHO4dOb6wZ9RQbJIT689y/I6Oo6i5ikIEork4XibFjdkOsu4M8r73S9jx1 7b1dJSt2vFFgE8K/SYVu3I/jCG0gVi68N/vMikCkUiLrtcTYsZtJ2srL6cUPKjc7fs8PzfQxAiJ wgb8dzPgL9Op83y5PYL8KS5jbDn0QxxeyfdUW+EzhpFPAaZ/NW7qpus+ckI1aOKznsyJ6MKUUqR eNSxDB5cqg5S4PglQwMjKmbSRAu7LCLYElXg0ZeoZoP6XzKMDHZfBaSVQ/Jp9QbY726cz0sf8aq uIF++GAk8We3TxAPMCfk3I X-Google-Smtp-Source: AGHT+IH/5QF76dST+qUgMVrwgOvWi+w3BTNe4avm4/XQxOoN/xj1mZO4lOmC/OH/RU/a7R7ECgkHJA== X-Received: by 2002:a17:907:940e:b0:b72:d577:11cc with SMTP id a640c23a62f3a-b8035641f7dmr3115325066b.12.1766858766594; Sat, 27 Dec 2025 10:06:06 -0800 (PST) Received: from mitya-t14-2025 ([2a02:a31b:20c3:6680:3d12:d2ea:4ee0:347a]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037a60569sm2796394566b.4.2025.12.27.10.06.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Dec 2025 10:06:06 -0800 (PST) Date: Sat, 27 Dec 2025 19:06:03 +0100 From: Dmytro Maluka To: Baolu Lu Cc: David Woodhouse , iommu@lists.linux.dev, Joerg Roedel , Will Deacon , Robin Murphy , linux-kernel@vger.kernel.org, "Vineeth Pillai (Google)" , Aashish Sharma , Grzegorz Jaszczyk , Chuanxiao Dong , Kevin Tian Subject: Re: [PATCH 1/2] iommu/vt-d: Ensure memory ordering in context entry updates Message-ID: References: <20251221014302.17738-1-dmaluka@chromium.org> <20251221014302.17738-2-dmaluka@chromium.org> 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=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Dec 23, 2025 at 02:10:45PM +0800, Baolu Lu wrote: > On 12/21/25 21:11, Dmytro Maluka wrote: > > On Sun, Dec 21, 2025 at 05:04:27PM +0800, Baolu Lu wrote: > > > On 12/21/25 09:43, Dmytro Maluka wrote: > > > > static inline void context_set_present(struct context_entry *context) > > > > { > > > > - context->lo |= 1; > > > > + context_set_bits(&context->lo, 1 << 0, 1); > > > > } > > > > > > How about adding a smp_wmb() before setting the present bit? Maybe it's > > > unnecessary for x86 architecture, but at least it's harmless and more > > > readable. Or not? > > > > > > static inline void context_set_present(struct context_entry *context) > > > { > > > smp_wmb(); > > > context_set_bits(&context->lo, 1ULL << 0, 1ULL); > > > } > > > > Maybe... And if so, then in pasid_set_present() as well? > > > > Actually this would make a slight behavioral difference even on x86: > > right now this patch only provides ordering of context entry updates > > between each other, while smp_wmb() would add a full compiler barrier > > here. > > > > So this barrier may be redundant as long as we always use these > > context_*() helpers (and thus always use WRITE_ONCE) for any updates of > > context entries. On the other hand, it might make it more robust if we > > still occasionally do that without WRITE_ONCE, for example in > > context_entry_set_pasid_table() which I also changed to use WRITE_ONCE > > in this patch. > > Fair point. It is somewhat redundant. However, I would suggest adding a > comment there. For example: > > static inline void context_set_present(struct context_entry *context) > { > /* > * smp_wmb() is unnecessary here because x86 hardware naturally > * keeps writes in order and all context entry modifications > * use WRITE_ONCE(). > */ > context_set_bits(&context->lo, 1ULL << 0, 1ULL); > } > > So that people are still aware of this when porting this driver to > platforms with a weak memory model. What I actually had in mind was to add smp_wmb() here anyway. It might be useful as an extra safety measure in case we still forget to use WRITE_ONCE in some cases, and its performance cost would be virtually non-existent, I guess. Done in v2.