Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp1678577imi; Sat, 23 Jul 2022 13:40:58 -0700 (PDT) X-Google-Smtp-Source: AGRyM1usgGWG7j43Hx46Cp/R9o9u4I1O9xRYBRwybnSXLniqnOPvjgaXm6dnKX5BinhvdV9NVcHg X-Received: by 2002:a17:907:87b0:b0:72b:9f0d:3f89 with SMTP id qv48-20020a17090787b000b0072b9f0d3f89mr4375962ejc.734.1658608858635; Sat, 23 Jul 2022 13:40:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658608858; cv=none; d=google.com; s=arc-20160816; b=x5Rgkm2qVHHnCiFoSV6JfXO5e1luAtNfNFJe8Q723trIX9RbzWeObc83U//eoegPwu z/7NNX5MR5C37+wV3VDNBvhKVseTCLhOXzhWqNItm7FreNJPSdaJrGCDWuN1XxI02q6E j/h++SqaYq7rR2CnW6yQliBITuGD4u76dXj8MlpNyzuPb/a5E3MmooSpnXqfCVIY8Y4r B2fMqD2Khpv95XIiaA4gJHuX2cCAlP7SgyUaj9h/b33T6dCxaIxiqDd7IATpYXwP8EaH JKEQLlK4MWKM3EOA5lBL2RwAKApWD2+KB7l/GJlZ2J+u2ZYt5v//qj/Td6pszCxT3gx6 1XMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:feedback-id:dkim-signature :dkim-signature; bh=JobHjI4vPeM2BF7bd/XNMmcC9Kn1HoQurkd99RcLsRk=; b=kiJ2zQH0yklL+9g2Qb+TYcFtpdMKZQNg9q2SFIghXf/KCQEmXCD2mtYVCLX+Gh/bje 6T+6R4llva72kqUEsMY2G8xhChuSXfkG3aY2ZA5SK3PG8N12pxm/Mr6KBpO0WugpXDA0 E0wGj/XmnKVVx4ZwlubpYjdidFMCP3ewaxQyEplYbVl3Rmt/JDtz5rN8mEk+Ig4qBscK jdOicL4AbTsyq44XiGj9c/QTylOXi8HKi19DzUL8cJGFkvsopZoWGB0qhDfTZWhYQVLy 9gWLx2xaxPp/FM/3mO2K88Y+/khQo7/e44pwKjCNM9Ipy9ZVuVTnyIdVWFpA00YU/B1o MObg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@invisiblethingslab.com header.s=fm3 header.b=MWTbsxQI; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=BQzLN7kw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id em4-20020a056402364400b0043acc275debsi4000068edb.296.2022.07.23.13.40.33; Sat, 23 Jul 2022 13:40:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@invisiblethingslab.com header.s=fm3 header.b=MWTbsxQI; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=BQzLN7kw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236569AbiGWU2L (ORCPT + 99 others); Sat, 23 Jul 2022 16:28:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236450AbiGWU2C (ORCPT ); Sat, 23 Jul 2022 16:28:02 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B847140B9; Sat, 23 Jul 2022 13:28:01 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id B7266320024A; Sat, 23 Jul 2022 16:27:58 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Sat, 23 Jul 2022 16:27:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding:date :date:from:from:in-reply-to:message-id:mime-version:reply-to :sender:subject:subject:to:to; s=fm3; t=1658608078; x= 1658694478; bh=JobHjI4vPeM2BF7bd/XNMmcC9Kn1HoQurkd99RcLsRk=; b=M WTbsxQI9l4G7tqQAiHf/K7oMTU8ufWVr4ldV3R0crGVCTUJE7fJXbX/llcvh7KRu lMPM4KBNzZXu+MCHVaVLJQ0vLXz6MvmZsaqgDYfLZ4LJ14ywaAxJBJmLhz8um+EW k7IzfudSehvF4XvP4qQma6b8jgN2bz148Fdt6Yt+6d8M5tufHxPp55tYcCM2qKUa AYxF2DvjnVWkrL/qH2HxZEmzjG/JCRLw22jYZo/5WVhG4frOZki37ELYn0CVoGO4 7ORJfy/Cr/ZwsgiqTSIevzoBtjgL4Kf/ojeISpBEqc1eKHbu+qZhcF2WSCHN5rc5 UqLNwgbiVCjkEGxQwZn/A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1658608078; x=1658694478; bh=JobHjI4vPeM2BF7bd/XNMmcC9Kn1HoQurkd 99RcLsRk=; b=BQzLN7kwQvOQTpo8U3OTqq0SwNGL/plAlnFsyOgbYUHXhPgDTuE Ow0WJS1uDHRgtvX6+v3V2jy+yZohTe8uG+k8qH/8cwoHhxr9rZZzpAnEE39A7F7U vmR/K50G5UxQFjvDe06/kn6PxIbeVr9nrDsPaaWJ85y6C7zKo7aJsfV2r05HpZwC FcNsswMDcMZsLMNOUVJF03H5qTfEl89C4kA999nfCRI30K+0Wa/kznBB5Z54GKnL /l9SClT6onhEurr+kr0nJEU5bp9RBu8qn8PoHk/0DRiMVahfQVcMcTtG6JhmzQ94 N7EPeagF7IvLMo3QXMSu4z0uaeTP2PzmO2A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvddtgedgudehfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkffoggfgsedtkeertdertddtnecuhfhrohhmpeffvghmihcu ofgrrhhivgcuqfgsvghnohhurhcuoeguvghmihesihhnvhhishhisghlvghthhhinhhgsh hlrggsrdgtohhmqeenucggtffrrghtthgvrhhnpedvfeegkedvkefgffegkefhieejtdff keehhfelheefjeeutefgleeggfdtveeileenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpeguvghmihesihhnvhhishhisghlvghthhhinhhgshhl rggsrdgtohhm X-ME-Proxy: Feedback-ID: iac594737:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 23 Jul 2022 16:27:57 -0400 (EDT) From: Demi Marie Obenour To: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Jens Axboe Cc: Demi Marie Obenour , xen-devel@lists.xenproject.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH] Implement diskseq checks in blkback Date: Sat, 23 Jul 2022 16:27:15 -0400 Message-Id: <20220723202715.1347-1-demi@invisiblethingslab.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE autolearn=ham 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 This allows specifying a disk sequence number in XenStore. If it does not match the disk sequence number of the underlying device, the device will not be exported and a warning will be logged. Userspace can use this to eliminate race conditions due to major/minor number reuse. Older kernels will ignore this, so it is safe for userspace to set it unconditionally. Signed-off-by: Demi Marie Obenour --- I'm marking this patch as RFC because I have not tested it beyond compiliation, and because I want to get feedback on the API before I put more effort into it. drivers/block/xen-blkback/xenbus.c | 35 ++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index 97de13b14175eb8ced14d1649a3be461a464ee8a..cb531236b19709c791a82c868bfb4ed9aa284485 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -480,7 +480,7 @@ MODULE_PARM_DESC(feature_persistent, static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, unsigned major, unsigned minor, int readonly, - int cdrom) + bool cdrom, u64 diskseq) { struct xen_vbd *vbd; struct block_device *bdev; @@ -508,6 +508,25 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, xen_vbd_free(vbd); return -ENOENT; } + + if (diskseq != (u64)-1) { + struct gendisk *disk = bdev->bd_disk; + if (unlikely(disk == NULL)) { + pr_err("xen_vbd_create: device %08x has no gendisk\n", + vbd->pdevice); + xen_vbd_free(vbd); + return -EFAULT; + } + + if (unlikely(disk->diskseq != diskseq)) { + pr_warn("xen_vbd_create: device %08x has incorrect sequence " + "number 0x%llx (expected 0x%llx)\n", + vbd->pdevice, disk->diskseq, diskseq); + xen_vbd_free(vbd); + return -ENODEV; + } + } + vbd->size = vbd_sz(vbd); if (cdrom || disk_to_cdi(vbd->bdev->bd_disk)) @@ -712,6 +731,7 @@ static void backend_changed(struct xenbus_watch *watch, int cdrom = 0; unsigned long handle; char *device_type; + unsigned long long diskseq; pr_debug("%s %p %d\n", __func__, dev, dev->otherend_id); @@ -730,6 +750,17 @@ static void backend_changed(struct xenbus_watch *watch, return; } + err = xenbus_scanf(XBT_NIL, dev->nodename, "diskseq", "%llx", &diskseq); + if (err == -ENOENT) { + diskseq = (uint64_t)-1; + } else if (err != 1) { + xenbus_dev_fatal(dev, err, "reading diskseq"); + return; + } else if (diskseq == (uint64_t)-1) { + xenbus_dev_fatal(dev, err, "UINT64_MAX is not a valid diskseq"); + return; + } + if (be->major | be->minor) { if (be->major != major || be->minor != minor) pr_warn("changing physical device (from %x:%x to %x:%x) not supported.\n", @@ -763,7 +794,7 @@ static void backend_changed(struct xenbus_watch *watch, be->minor = minor; err = xen_vbd_create(be->blkif, handle, major, minor, - !strchr(be->mode, 'w'), cdrom); + !strchr(be->mode, 'w'), cdrom, diskseq); if (err) xenbus_dev_fatal(dev, err, "creating vbd structure"); -- Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab