Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp164504imm; Tue, 14 Aug 2018 16:17:58 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyb0qk9sz0W+25ApGA6LJjrnB2onT7id4UDy0eBD0us2E9cSU8VBTvlFUbTqHO9PjgCJ77X X-Received: by 2002:a65:6143:: with SMTP id o3-v6mr23417999pgv.52.1534288678627; Tue, 14 Aug 2018 16:17:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534288678; cv=none; d=google.com; s=arc-20160816; b=nzQAXTO1m0b8o1s6TVkCr2qKglQz8eez9H4RkSRKFH+FIMR46Il0rQGMB3xYU9k/gW TGScJzz6tsxbD5c6GhIUGCuc09iqhdgNByUgBqBaR2TDpc1bsqWKDtDrSSfieSSB2BDF TDAoqglWql4eFkxR4v9oxRgVbuoHqAYH6RjxO1lBe7anNvI0YQleoHdxTrBl+2C/I/SY 9K73KAosuUs/D5vHo6gpYWbV82lP8HFwp7Jq7ucgyH/pySTP3emiRaxU/asXobYOZmLV GsQ2Ne58XyYND7ZLFASsKoUnc5uM3+BgNEmfZW/gDnVhjbpFsNVUyJHm4frtLka8rGIW l4iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=24jK8A7jkNIu2WgqU9zP0yRp+02coOoQHaoLJQ7Q6O0=; b=D3HEyLSVxUaD5hUioQlCfv1VVKlGGFQwqaVMSpxIb9504aNk5FluwPMobyQybfbxYK SJyv/0SEh2kv9A8CTaTLf/g8fgOFbFrmZlqWHQ1HdfVZ1vxCebeFbLZe9jZ+MImGS/kF DeMhndDOzOqHpzV72sO5WEQ5aLA94o9ByTic2sgekgITv8ydTi/ajpCR1vJZGe+47NdI Hh+e/B9U+tjT7PCK2o2sJH6ek8xVybvO6+PulClD67Wr6NS7EcUGeu7hIKAP4PHvxbEZ mZA8pgqDyZ+8GK89p8TPSd7+1eQdx/VwHWxefQzODQaNz+/39dLkA2GHYC1JDhsjgAmA VkcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=Hqgmc9k4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q8-v6si19839444pfh.353.2018.08.14.16.17.43; Tue, 14 Aug 2018 16:17:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=Hqgmc9k4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732521AbeHOCGU (ORCPT + 99 others); Tue, 14 Aug 2018 22:06:20 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:50316 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729705AbeHOCGU (ORCPT ); Tue, 14 Aug 2018 22:06:20 -0400 Received: by mail-it0-f68.google.com with SMTP id j81-v6so20912663ite.0 for ; Tue, 14 Aug 2018 16:16:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=24jK8A7jkNIu2WgqU9zP0yRp+02coOoQHaoLJQ7Q6O0=; b=Hqgmc9k47hrE4UoBhiZSh9KyXSgZ6f1L221vCvMqO1pRK2BXopaH2ox0thUqjonmYO w4kHOi0yZjLKjSmhaQ0FvvwmrFumBKqtmv89A84m3uABXVqechxEj6q3M8IA8tLfF18m HWQe2Uz6WXRqKzbc7Yq0/+J7Pl7DEFXkr2ozU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=24jK8A7jkNIu2WgqU9zP0yRp+02coOoQHaoLJQ7Q6O0=; b=CmPT0evOpotl+MQFNThjWpvsOmWi9Efhnpp/Bd8AdLsgv1VPRaiTVHZ/wWJ4gLNu3t Wexvi7bxYvEYjAqfYh7/4JqlAIm7N3gMWjP6jV0H0AGEMn54UHmXhT65qbAS/obGsBGG d+GKQffbl1XPM8T808V6Cl2dTmLEII59UQvmVVRnj/akc0Dv6frKo6SCH3LgmFkrpVgT 49fdoyj/iKyc0UWctQZ1kJjMl3SR1blrcW/LKpR9hB6ECj8n9NIxezm86gP1J/YF9sKM CyDItDMKPjJXXhTfL4yIEjSsEkOiCGZ1vBkPb/oNrMIf4cbIeUvfGrDbsjTcXCIADK/5 456A== X-Gm-Message-State: AOUpUlGplUam0dJE7AuWmD4CoS1u+p3MdTB4wqhGmi+zNxx83kgCexdF 0WwmuzD9MHZY7piOFDy189bO/BJngv78iiqqecw= X-Received: by 2002:a02:1bdc:: with SMTP id 89-v6mr20505299jas.72.1534288613120; Tue, 14 Aug 2018 16:16:53 -0700 (PDT) MIME-Version: 1.0 References: <20180814221735.62804-1-wnukowski@google.com> <20180814225716.GA3224@localhost.localdomain> In-Reply-To: <20180814225716.GA3224@localhost.localdomain> From: Linus Torvalds Date: Tue, 14 Aug 2018 16:16:41 -0700 Message-ID: Subject: Re: [PATCH] Bugfix for handling of shadow doorbell buffer. To: keith.busch@linux.intel.com Cc: wnukowski@google.com, Jens Axboe , Sagi Grimberg , Linux Kernel Mailing List , linux-nvme , Keith Busch , yigitfiliz@google.com, Christoph Hellwig Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Guys, you're both wrong. On Tue, Aug 14, 2018 at 03:17:35PM -0700, Michal Wnukowski wrote: > > With memory barrier in place, the volatile keyword around *dbbuf_ei is > redundant. No. The memory barrier enforces _ordering_, but it doesn't enforce that the accesses are only done once. So when you do > *dbbuf_db = value; to write to dbbuf_db, and > *dbbuf_ei to read from dbbuf_ei, without the volatile the write (or the read) could be done multiple times, which can cause serious confusion. So the "mb()" enforces ordering, and the volatile means that the accesses will each be done as one single access. Two different issues entirely. However, there's a more serious problem with your patch: > + /* > + * Ensure that the doorbell is updated before reading > + * the EventIdx from memory > + */ > + mb(); Good comment. Except what about the other side? When you use memory ordering rules, as opposed to locking, there's always *two* sides to any access order. There's this "write dbbuf_db" vs "read dbbuf_ei" ordering. But there's the other side: what about the side that writes dbbuf_ei, and reads dbbuf_db? I'm assuming that's the actual controller hardware, but it needs a comment about *that* access being ordered too, because if it isn't, then ordering this side is pointless. On Tue, Aug 14, 2018 at 3:56 PM Keith Busch wrote: > > You just want to ensure the '*dbbuf_db = value' isn't reordered, right? > The order dependency might be more obvious if done as: > > WRITE_ONCE(*dbbuf_db, value); > > if (!nvme_dbbuf_need_event(READ_ONCE(*dbbuf_ei), value, old_value)) > return false; > > And 'volatile' is again redundant. Yes, using READ_ONCE/WRITE_ONCE obviates the need for volatile, but it does *not* impose a memory ordering. It imposes an ordering on the compiler, but not on the CPU, so you still want the "mb()" there (or the accesses need to be to uncached memory or something, but then you should be using "readl()/writel()", so that's not the case here). Linus