Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp258237imm; Tue, 14 Aug 2018 18:36:40 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzi+dCSyowjJJIxV+bFsgnSDHFu8r5VNgpOxntpYCJtGVG2vRu4ljXONjG1++hs960QY4ge X-Received: by 2002:a17:902:b70f:: with SMTP id d15-v6mr14662302pls.53.1534297000638; Tue, 14 Aug 2018 18:36:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534297000; cv=none; d=google.com; s=arc-20160816; b=qtKBFstZCDCH5wJglV8U/D+F2e2UfeT4D+zoSsigOQUE4sv9aAPKkqYRajaqREdYst 4LabW+TH6C+wCyNbRFM96DMbr1sKGRLTKiMu2mUKomzJLT+lDW3PHf4PPHXbvuIFI3Ls 23HKyW6qggoCAhA8xRkJyjjUBZcE7fxVhyRQmVBRBOwSC5bGJbbnc6yEuO1Gj9V0dR+n WIkMPv7rBj51yZhInitP0vy8F8DvgZL08jD3rCWl9vJXtFdWHfouaRux+2j+a6/JC5Bl HuiHy79CUA1qa2zaoOxSS66YO9om5rUKGYSSNnNK/lCNHJjtu5mTNTd3OZvQgVPLBhfT sdTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=R/dSXm1U+oMTZJvbM+HvIefHaXvMTPgkOu4CPkg8DnE=; b=NFcOgnWnhaGKaSx/8y5V/Rl7gAVHaz8nHAgKeFcw/EmYTIuXiVzmxXz4HET3BelFLp B3f91ib6sYekMNEJo/5WEA+rL/ZPlo6MVuXdihnCJ6H40mO20y/kHNm0ezZ0msFIYRSU QIsJz0avmwdvEZOo3umvnPhqzpFRttWsF2KjyDyh2e6Qi17mrMguH6fbvufkWReIrllJ HDf04MQcNH5Cmyp0TBnVQRw8Ly06zFlI6MgwobNEZge5rIv3V4H/qE+CxNEcD52iUF/J IIoO063TAmxZFjlxGhiYBu7WYseIiETUD5NqDv45Q94J8/AHWCwU4mQgHHLHUcwUPxpq Z4gA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=kbVKRa0W; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h21-v6si23259076pgi.430.2018.08.14.18.36.25; Tue, 14 Aug 2018 18:36:40 -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=@google.com header.s=20161025 header.b=kbVKRa0W; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726020AbeHOEZM (ORCPT + 99 others); Wed, 15 Aug 2018 00:25:12 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:32993 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725843AbeHOEZM (ORCPT ); Wed, 15 Aug 2018 00:25:12 -0400 Received: by mail-pg1-f193.google.com with SMTP id r5-v6so9925216pgv.0 for ; Tue, 14 Aug 2018 18:35:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=R/dSXm1U+oMTZJvbM+HvIefHaXvMTPgkOu4CPkg8DnE=; b=kbVKRa0WYe4/TU1hjtJT66V2Krv47MraHrc8wUMzAtar0eWvUAkzFdDPDuo085DEXJ 9BzVIjGpevSmMOcfXxre5+NzvxiPxbSk0dzpwWTZxlCqqMlg4kR8DTxD/vJb5SGoo2Zp ZQ6eYHVck7SUUdWGP5bjDXEAIHwuPEV079AbQAE4zLGR00WXan9rwQKY8faFYwvODjlR w4k63ga8UgOrYxaCUCAYfyvDwc1QD14+s1MshlF275ZYdb89PjYXTNGJfvEk5QSZEt10 /iKm2r9e3YNxKslSPzeStnz/uCUx/IQwX36l532WlotfVEfjKq5cX5eSA4Rd0EeyqHT/ 0TcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=R/dSXm1U+oMTZJvbM+HvIefHaXvMTPgkOu4CPkg8DnE=; b=hXjGgFBxwrj2weCr2UxlhaUKAt3+ChkkIpUOM1eCTtK9JvUza8T8nsyRs7MTXW/Vza MVRh0bpL18vMAc3lEm2aEtga74JhFB4hr1QwFLjcW9pt3T3M+PTG1MedzfCpyHfTEldk 4vARJMChcptqfZQi/z9pev2NNUNcDhtOcH2Ly/5Zr8ONVSaM0EQf5whkWTna60cWpO0b 1V/NaX1HIYe/X9DXYpablF7Q8ZVzID9BzfVv0rSxePdF/4ytqh+sre303+zt74T1jrhQ xWgOlXKg6wbxY3ZQR6rrTvSUCjsZT4dCCqupJp2ovdMOh4cazJ4NIsz0knz+nnNEDbrM 1lbw== X-Gm-Message-State: AOUpUlEK/kmsRkIHzFz2hGosmmp69JzUdzon5OFrMZmAOV7/KWVID0du j3+Ao5jqQIk87epuJKhLN4PCow== X-Received: by 2002:a63:2506:: with SMTP id l6-v6mr22988247pgl.237.1534296919094; Tue, 14 Aug 2018 18:35:19 -0700 (PDT) Received: from wnukowski-desktop.sea.corp.google.com ([2620:0:1009:11:cdf9:e330:7b8e:1961]) by smtp.gmail.com with ESMTPSA id d22-v6sm45317760pfk.69.2018.08.14.18.35.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Aug 2018 18:35:18 -0700 (PDT) Subject: Re: [PATCH] Bugfix for handling of shadow doorbell buffer. To: Linus Torvalds , keith.busch@linux.intel.com Cc: Jens Axboe , Sagi Grimberg , Linux Kernel Mailing List , linux-nvme , Keith Busch , yigitfiliz@google.com, Christoph Hellwig References: <20180814221735.62804-1-wnukowski@google.com> <20180814225716.GA3224@localhost.localdomain> From: Michal Wnukowski Message-ID: Date: Tue, 14 Aug 2018 18:35:16 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/14/2018 04:16 PM, Linus Torvalds wrote: > 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. > I got confused after comaring disassembly of this code with and without volatile keyword. Thanks for the correction. > > 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. > The other side in this case is not actual controller hardware, but virtual one (the regular hardware should rely on normal MMIO doorbells). I spent some time going through the code of internal hypervisor and double-checking all guarantees around memory access before asking the same question: "what about the other side?". This execution ordering is mentioned in NVMe spec under "Controller Architecture", and it turned out that the NVMe driver itself had missing memory barrier. Thanks, Michal