From patchwork Fri Apr 24 06:25:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chirantan Ekbote X-Patchwork-Id: 11507185 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F061192A for ; Fri, 24 Apr 2020 06:26:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D2C5D20704 for ; Fri, 24 Apr 2020 06:26:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="BLtx0N5L" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726028AbgDXG0J (ORCPT ); Fri, 24 Apr 2020 02:26:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725898AbgDXG0J (ORCPT ); Fri, 24 Apr 2020 02:26:09 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82813C09B045 for ; Thu, 23 Apr 2020 23:26:08 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id y6so3538454pjc.4 for ; Thu, 23 Apr 2020 23:26:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gfc0cFO2L1HUkwddTCsuj4a1zB9/jwWzyBDO+mCQarU=; b=BLtx0N5LC85qAEv11FxLkhD7+543mklwOA7DxGaz3qkPFpdnaz1m7zbbl3uVeEGQ0D ORDeFnGX68cXXK4ozkw24hStQgus/kwSbJcFYz8wTJwea9ogyQ9HGMSFUCy9lU0AgVZC D2/IIWNRLKY2JTEZ7YgoDEeOi2H30WOoVG8Ds= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gfc0cFO2L1HUkwddTCsuj4a1zB9/jwWzyBDO+mCQarU=; b=aqsCRmD4PbgufvalfV9Qb7qzfsSyJHTSe1dJd8WHqRfAg0Qv3XFVJqPJSYpmNO/Diu 4FarKFy2c12aVh/wBeeJnEMxWY87YyFcc4NrYs9iXZfFb3RUXvSNcLQcqgW1f7DA0pZu GByXjAV1uB5TO2hi8UJoUT8987P3gPGp4bu0MueRCWPm79p6NyBwQBds00ikYo8XBFM3 L3NGT1fUZStY3yl0Bs2brhVnGlq9jqiMFqANtwZTFJaLvfqDd0kCqqDAUf3iczvCdezS SOJrMUEKnOdrP8D8umNUatVNWm/0ApjfMJD66xKJJqSLep49xsuMRn/zPM2F7H+Sz9YB xnuw== X-Gm-Message-State: AGi0PuZs8fEg8Dqa1SIQrf8+t+pOPxOoVKmHngRiGFDvHZX4J/2UbeXk HxGymIaBUqU4RR/xM8k2mLX1jQ== X-Google-Smtp-Source: APiQypI9p+1f+TDu6sMOE3JqkpBE7ZVPzayuw85gi85pw3JPaz8plV06L9tpj4eXp2x3bj7MukOQxA== X-Received: by 2002:a17:90a:589:: with SMTP id i9mr4611312pji.156.1587709568073; Thu, 23 Apr 2020 23:26:08 -0700 (PDT) Received: from localhost ([2401:fa00:8f:2:1c5:cb1a:7c95:326]) by smtp.gmail.com with ESMTPSA id i190sm4656562pfe.114.2020.04.23.23.26.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Apr 2020 23:26:07 -0700 (PDT) From: Chirantan Ekbote To: Miklos Szeredi Cc: Vivek Goyal , Stefan Hajnoczi , linux-fsdevel@vger.kernel.org, virtio-fs@redhat.com, Dylan Reid , Suleiman Souhlal , Chirantan Ekbote Subject: [PATCH 1/2] fuse: virtiofs: Fix nullptr dereference Date: Fri, 24 Apr 2020 15:25:39 +0900 Message-Id: <20200424062540.23679-1-chirantan@chromium.org> X-Mailer: git-send-email 2.26.2.303.gf8c07b1a785-goog MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org virtiofs device implementations are allowed to provide more than one request queue. In this case `fsvq->fud` would not be initialized, leading to a nullptr dereference later during driver initialization. Make sure that `fsvq->fud` is initialized for all request queues even if the driver doesn't use them. Signed-off-by: Chirantan Ekbote Reviewed-by: Stefan Hajnoczi --- fs/fuse/virtio_fs.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c index bade747689033..d3c38222a7e4e 100644 --- a/fs/fuse/virtio_fs.c +++ b/fs/fuse/virtio_fs.c @@ -1066,10 +1066,13 @@ static int virtio_fs_fill_super(struct super_block *sb) } err = -ENOMEM; - /* Allocate fuse_dev for hiprio and notification queues */ - for (i = 0; i < VQ_REQUEST; i++) { + /* Allocate fuse_dev for all queues except the first request queue. */ + for (i = 0; i < fs->nvqs; i++) { struct virtio_fs_vq *fsvq = &fs->vqs[i]; + if (i == VQ_REQUEST) + continue; + fsvq->fud = fuse_dev_alloc(); if (!fsvq->fud) goto err_free_fuse_devs; From patchwork Fri Apr 24 06:25:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chirantan Ekbote X-Patchwork-Id: 11507187 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7630A92A for ; Fri, 24 Apr 2020 06:26:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B09E20706 for ; Fri, 24 Apr 2020 06:26:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="bCK/J8SW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726386AbgDXG0V (ORCPT ); Fri, 24 Apr 2020 02:26:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725898AbgDXG0U (ORCPT ); Fri, 24 Apr 2020 02:26:20 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85025C09B045 for ; Thu, 23 Apr 2020 23:26:20 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id ms17so3572783pjb.0 for ; Thu, 23 Apr 2020 23:26:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ILlNwQ7IYNn33LRxFCAi5oYlzntM/30JEoLe+sVzVCg=; b=bCK/J8SWnJEv/4om3fKbfMX03oFef6Um4Z4bT+Wb0xOqocFNWWaSFw/R/5JB/myuMH PDQRuFN1K5bGSMli5b6UOEB+FdKQL3J4MeE7pd6+ZgL0nxDRiSImpqn+tqwl0UAit/Vl gBR18/OAc+Oate+v29u8eEdZDTvvXKEzhKJPM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ILlNwQ7IYNn33LRxFCAi5oYlzntM/30JEoLe+sVzVCg=; b=eKsfVG7q70+xboIjUcfqbfY35n5KYGH2vUjXR9/DCsKr1UyyKapKhZeiCphPxtoUBQ +ACDlSEFsqHNLgvtd6ZB+iH1oC1yHrXHtC7uSpOr4GXttRd1qohaSvW87a30SyeTTZEr dpDQvXAl+iGWJPNBJp8aLLn59ib7mXao4QTuIOXE7iaLoJdpi3OR0xhmQHGNIVAbYTNu BZW5FGgO7YuuHoJqhK/lqeFeXDoux+T0k8Dhb5Szj4m8eYD1wUXxUnFtjgmqT2uAbzO7 v1K+lxPSwE13FZiJB39F6HQicJP1ort33n6hlbLaJhzMsLnkUuyqvDW+jE+WMW/u+Vre LPbQ== X-Gm-Message-State: AGi0Pua10UPtfuMqLnZDnCJwQqYgtd/XRX7gYsxLE8FIIhKYvuPZC5Jz yZAb15/W7VTvSZtRF4lHkD/ff/FS40HXsg== X-Google-Smtp-Source: APiQypI3RSHLnfLFCiblw59wOL7Mdi44PgHmc0+JFHwEJif+N8ckhS1qRufYSIePwi0wPkahbZDkrA== X-Received: by 2002:a17:90a:7486:: with SMTP id p6mr4721190pjk.62.1587709580099; Thu, 23 Apr 2020 23:26:20 -0700 (PDT) Received: from localhost ([2401:fa00:8f:2:1c5:cb1a:7c95:326]) by smtp.gmail.com with ESMTPSA id c28sm4603644pfp.200.2020.04.23.23.26.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Apr 2020 23:26:19 -0700 (PDT) From: Chirantan Ekbote To: Miklos Szeredi Cc: Vivek Goyal , Stefan Hajnoczi , linux-fsdevel@vger.kernel.org, virtio-fs@redhat.com, Dylan Reid , Suleiman Souhlal , Chirantan Ekbote Subject: [PATCH 2/2] fuse: virtiofs: Add basic multiqueue support Date: Fri, 24 Apr 2020 15:25:40 +0900 Message-Id: <20200424062540.23679-2-chirantan@chromium.org> X-Mailer: git-send-email 2.26.2.303.gf8c07b1a785-goog In-Reply-To: <20200424062540.23679-1-chirantan@chromium.org> References: <20200424062540.23679-1-chirantan@chromium.org> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use simple round-robin scheduling based on the `unique` field of the fuse request to spread requests across multiple queues, if supported by the device. Signed-off-by: Chirantan Ekbote --- fs/fuse/dev.c | 4 ---- fs/fuse/fuse_i.h | 4 ++++ fs/fuse/virtio_fs.c | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 97eec7522bf20..cad9f76c2519c 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -25,10 +25,6 @@ MODULE_ALIAS_MISCDEV(FUSE_MINOR); MODULE_ALIAS("devname:fuse"); -/* Ordinary requests have even IDs, while interrupts IDs are odd */ -#define FUSE_INT_REQ_BIT (1ULL << 0) -#define FUSE_REQ_ID_STEP (1ULL << 1) - static struct kmem_cache *fuse_req_cachep; static struct fuse_dev *fuse_get_dev(struct file *file) diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index ca344bf714045..110b917d950a8 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -47,6 +47,10 @@ /** Number of dentries for each connection in the control filesystem */ #define FUSE_CTL_NUM_DENTRIES 5 +/* Ordinary requests have even IDs, while interrupts IDs are odd */ +#define FUSE_INT_REQ_BIT (1ULL << 0) +#define FUSE_REQ_ID_STEP (1ULL << 1) + /** List of active connections */ extern struct list_head fuse_conn_list; diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c index d3c38222a7e4e..c5129fd27930c 100644 --- a/fs/fuse/virtio_fs.c +++ b/fs/fuse/virtio_fs.c @@ -980,7 +980,7 @@ static int virtio_fs_enqueue_req(struct virtio_fs_vq *fsvq, static void virtio_fs_wake_pending_and_unlock(struct fuse_iqueue *fiq) __releases(fiq->lock) { - unsigned int queue_id = VQ_REQUEST; /* TODO multiqueue */ + unsigned int queue_id; struct virtio_fs *fs; struct fuse_req *req; struct virtio_fs_vq *fsvq; @@ -994,6 +994,8 @@ __releases(fiq->lock) spin_unlock(&fiq->lock); fs = fiq->priv; + queue_id = ((req->in.h.unique / FUSE_REQ_ID_STEP) % + (uint64_t)fs->num_request_queues) + VQ_REQUEST; pr_debug("%s: opcode %u unique %#llx nodeid %#llx in.len %u out.len %u\n", __func__, req->in.h.opcode, req->in.h.unique,