From patchwork Tue Feb 12 13:06:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 2128331 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id E2F563FD4F for ; Tue, 12 Feb 2013 13:08:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933261Ab3BLNIM (ORCPT ); Tue, 12 Feb 2013 08:08:12 -0500 Received: from mail-vb0-f44.google.com ([209.85.212.44]:48170 "EHLO mail-vb0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933230Ab3BLNG6 (ORCPT ); Tue, 12 Feb 2013 08:06:58 -0500 Received: by mail-vb0-f44.google.com with SMTP id fr13so29020vbb.17 for ; Tue, 12 Feb 2013 05:06:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=MsRf64Ee78wbEU1LjbsHpaO/T3CfBVRvPcn2mZxXS24=; b=AZb+9lO95HSMCpX1cDpYMJW3ofoKTSkbe5cqaHe+b2AN48H/O5NLfevIHfVqrJwEhk EmK6mXubOhXgMeJHp2d8UsNBzITQEgGo8xRN/NLcqb+Z6Djb8OCOiJsWrLEj0/m7PF+8 cjJSoB+djA5C912JjUVESQCg3TMNvRgENcKw1cHEAZCIlxkeQ4ExE/mAoTkRPm3roRQv UCR62MefN7gmexWK2toivL2D77CQDUyBDnbZWOR+efgkBYH6FXQUio+aEz8GyC36Y2DW 3gMS11ZwdKnwbVODgSyqJDJ24pZEeSOvwnut8+o2Cmu4X7lRrMpYMrLFQNKTzCTBwuSY aS1w== X-Received: by 10.220.119.147 with SMTP id z19mr23903403vcq.69.1360674417048; Tue, 12 Feb 2013 05:06:57 -0800 (PST) Received: from yakj.usersys.redhat.com (93-34-179-137.ip50.fastwebnet.it. [93.34.179.137]) by mx.google.com with ESMTPS id qj8sm64158235veb.2.2013.02.12.05.06.54 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 12 Feb 2013 05:06:56 -0800 (PST) From: Paolo Bonzini To: linux-kernel@vger.kernel.org Cc: Wanlong Gao , asias@redhat.com, mst@redhat.com, Rusty Russell , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, JBottomley@parallels.com, linux-scsi@vger.kernel.org Subject: [PATCH v3 5/5] virtio-scsi: reset virtqueue affinity when doing cpu hotplug Date: Tue, 12 Feb 2013 14:06:31 +0100 Message-Id: <1360674391-2661-6-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1360674391-2661-1-git-send-email-pbonzini@redhat.com> References: <1360674391-2661-1-git-send-email-pbonzini@redhat.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Wanlong Gao Add hot cpu notifier to reset the request virtqueue affinity when doing cpu hotplug. Cc: linux-scsi@vger.kernel.org Signed-off-by: Wanlong Gao [ The version that doesn't get/put_online_cpus is now called __virtscsi_set_affinity - Paolo ] Signed-off-by: Paolo Bonzini --- drivers/scsi/virtio_scsi.c | 31 +++++++++++++++++++++++++++++++ 1 files changed, 31 insertions(+), 0 deletions(-) diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c index a2bdae1..733307a 100644 --- a/drivers/scsi/virtio_scsi.c +++ b/drivers/scsi/virtio_scsi.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -109,6 +110,9 @@ struct virtio_scsi { /* Does the affinity hint is set for virtqueues? */ bool affinity_hint_set; + /* CPU hotplug notifier */ + struct notifier_block nb; + struct virtio_scsi_vq ctrl_vq; struct virtio_scsi_vq event_vq; struct virtio_scsi_vq req_vqs[]; @@ -734,6 +738,7 @@ static void __virtscsi_set_affinity(struct virtio_scsi *vscsi, bool affinity) } } + static void virtscsi_set_affinity(struct virtio_scsi *vscsi, bool affinity) { get_online_cpus(); @@ -741,6 +746,23 @@ static void virtscsi_set_affinity(struct virtio_scsi *vscsi, bool affinity) put_online_cpus(); } +static int virtscsi_cpu_callback(struct notifier_block *nfb, + unsigned long action, void *hcpu) +{ + struct virtio_scsi *vscsi = container_of(nfb, struct virtio_scsi, nb); + switch(action) { + case CPU_ONLINE: + case CPU_ONLINE_FROZEN: + case CPU_DEAD: + case CPU_DEAD_FROZEN: + __virtscsi_set_affinity(vscsi, true); + break; + default: + break; + } + return NOTIFY_OK; +} + static void virtscsi_init_vq(struct virtio_scsi_vq *virtscsi_vq, struct virtqueue *vq) { @@ -885,6 +907,13 @@ static int virtscsi_probe(struct virtio_device *vdev) if (err) goto virtscsi_init_failed; + vscsi->nb.notifier_call = &virtscsi_cpu_callback; + err = register_hotcpu_notifier(&vscsi->nb); + if (err) { + pr_err("virtio_scsi: registering cpu notifier failed\n"); + goto scsi_add_host_failed; + } + cmd_per_lun = virtscsi_config_get(vdev, cmd_per_lun) ?: 1; shost->cmd_per_lun = min_t(u32, cmd_per_lun, shost->can_queue); shost->max_sectors = virtscsi_config_get(vdev, max_sectors) ?: 0xFFFF; @@ -922,6 +951,8 @@ static void virtscsi_remove(struct virtio_device *vdev) scsi_remove_host(shost); + unregister_hotcpu_notifier(&vscsi->nb); + virtscsi_remove_vqs(vdev); scsi_host_put(shost); }