Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2900134pxb; Tue, 24 Aug 2021 10:10:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxanGPGm6GORhY/TRzVknic/GkL29YGM5RoLHqlF+RQ3PyoBfC/zCGe9hZjfAIVqpuKPIy+ X-Received: by 2002:aa7:c857:: with SMTP id g23mr44396808edt.219.1629825028869; Tue, 24 Aug 2021 10:10:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629825028; cv=none; d=google.com; s=arc-20160816; b=J4aF6cmrNrSGk9fBnmknXa4tDSoHW66a+mzc3nue4cxFJjGbhvdJJsztdN4cIROlKZ VTAk+PUyZQ9C4ViFxqvLu9T4c8cqbSnYikUuIyZ9vlfi/9Bxxn69ziD4PcBG7suEQD3W Xt++1h33bXhEQ98Xtt8mc9UjuOThwaSWqAKPvmrjbMmoRAGB+AGyW7b7lWCLWwb5GuhX bNJ5yRUrphh7jtrzTb+SJM33pWgpEsVBGaZDRV8d1ti6L7EKeqPeOXitRT1YM42I2KJm nPRngVkgjLg+SlOGYhsLX6H/NlcBXHCyjQ1HVv4pfxsKAShwGe2gGSIqQI6b/NF02JPv sEPw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yzkoju7Kvjy4EOChz6JrmyJrzqJhKa0Fzas5DZELQ/U=; b=LcuxHRUSTSlTrvelMmEMEDhnpRBNE9jLwqfyJKAal69kFUeaiKhu5CpM8h0M6GzGUp 75CSQEMtQ7A9pDpcuHrFi+SssPkv42DWCV1g9J/FsvBVW0YmjdfJc3OA+HdTXqro50U5 AMvK5i5cFl1rVUYhddqFg11bY6JzbgpLQGdXeyx9rnSaZtHuCTtiXCQGflnYcfvyp4TG uCA2BpEhbiCrZ8Ua05QOCi24aJxhUVSF2gfmJ2dShfpaQrTvJg/fnXtQSiJSZdc6APom pZhZV9nyJSCTdQzmHAFDs9NpqvHvYjxO88JHMFv0CmzTPl8CYo4DajKkCw1JuTzce6ur lHpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eZxZ1CBG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h10si19268025edk.552.2021.08.24.10.10.03; Tue, 24 Aug 2021 10:10:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eZxZ1CBG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238985AbhHXRJH (ORCPT + 99 others); Tue, 24 Aug 2021 13:09:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:46234 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239289AbhHXRGt (ORCPT ); Tue, 24 Aug 2021 13:06:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 49097619E3; Tue, 24 Aug 2021 16:59:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824389; bh=ms0iJJZjoosPyoIQUq0BQ5ekHMSHPaTzHmcbg8oCFhA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eZxZ1CBGyFgmgmb6sefr0x1VmJptmyTgaGhioLTcBIKJ2iHPlTzOtlUNkyEk3wTwP ngrEQCLor4ysZSWVmA+F/dK8J41+0jtOurXvux4aETVfz3lQWn+xZ1H65pnIA8kX/+ o6eMvoqPDG3rt90u/BCZiuM8XqTHWWK6YI7hULLwcfy/gocfdVUqmL9TxQjdCCxTtZ X4NB3ABrTicZjTflBkflsu1pInKL82eSXq/OPI3vMkjB95G/u0mEkTCh5vjRwgeHy3 ykedbXTs8BdFXskjEZIjC1uaPyJZPeYri3jbtcdWg8Smsxy5BPgj5VirwfhulhDmeq F/IJsUXj8DS6w== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Parav Pandit , "Michael S . Tsirkin" , Sasha Levin Subject: [PATCH 5.10 40/98] virtio: Protect vqs list access Date: Tue, 24 Aug 2021 12:58:10 -0400 Message-Id: <20210824165908.709932-41-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824165908.709932-1-sashal@kernel.org> References: <20210824165908.709932-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.61-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.10.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.10.61-rc1 X-KernelTest-Deadline: 2021-08-26T16:58+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Parav Pandit [ Upstream commit 0e566c8f0f2e8325e35f6f97e13cde5356b41814 ] VQs may be accessed to mark the device broken while they are created/destroyed. Hence protect the access to the vqs list. Fixes: e2dcdfe95c0b ("virtio: virtio_break_device() to mark all virtqueues broken.") Signed-off-by: Parav Pandit Link: https://lore.kernel.org/r/20210721142648.1525924-4-parav@nvidia.com Signed-off-by: Michael S. Tsirkin Signed-off-by: Sasha Levin --- drivers/virtio/virtio.c | 1 + drivers/virtio/virtio_ring.c | 8 ++++++++ include/linux/virtio.h | 1 + 3 files changed, 10 insertions(+) diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c index 42e09cc1b8ac..84b5dec5d29c 100644 --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c @@ -357,6 +357,7 @@ int register_virtio_device(struct virtio_device *dev) virtio_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE); INIT_LIST_HEAD(&dev->vqs); + spin_lock_init(&dev->vqs_list_lock); /* * device_add() causes the bus infrastructure to look for a matching diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 71e16b53e9c1..6b7aa26c5384 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -1668,7 +1668,9 @@ static struct virtqueue *vring_create_virtqueue_packed( cpu_to_le16(vq->packed.event_flags_shadow); } + spin_lock(&vdev->vqs_list_lock); list_add_tail(&vq->vq.list, &vdev->vqs); + spin_unlock(&vdev->vqs_list_lock); return &vq->vq; err_desc_extra: @@ -2126,7 +2128,9 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index, memset(vq->split.desc_state, 0, vring.num * sizeof(struct vring_desc_state_split)); + spin_lock(&vdev->vqs_list_lock); list_add_tail(&vq->vq.list, &vdev->vqs); + spin_unlock(&vdev->vqs_list_lock); return &vq->vq; } EXPORT_SYMBOL_GPL(__vring_new_virtqueue); @@ -2210,7 +2214,9 @@ void vring_del_virtqueue(struct virtqueue *_vq) } if (!vq->packed_ring) kfree(vq->split.desc_state); + spin_lock(&vq->vq.vdev->vqs_list_lock); list_del(&_vq->list); + spin_unlock(&vq->vq.vdev->vqs_list_lock); kfree(vq); } EXPORT_SYMBOL_GPL(vring_del_virtqueue); @@ -2274,10 +2280,12 @@ void virtio_break_device(struct virtio_device *dev) { struct virtqueue *_vq; + spin_lock(&dev->vqs_list_lock); list_for_each_entry(_vq, &dev->vqs, list) { struct vring_virtqueue *vq = to_vvq(_vq); vq->broken = true; } + spin_unlock(&dev->vqs_list_lock); } EXPORT_SYMBOL_GPL(virtio_break_device); diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 55ea329fe72a..8ecc2e208d61 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -110,6 +110,7 @@ struct virtio_device { bool config_enabled; bool config_change_pending; spinlock_t config_lock; + spinlock_t vqs_list_lock; /* Protects VQs list access */ struct device dev; struct virtio_device_id id; const struct virtio_config_ops *config; -- 2.30.2