From patchwork Tue Nov 3 14:34:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877779 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 1822492A for ; Tue, 3 Nov 2020 14:35:20 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9914D22370 for ; Tue, 3 Nov 2020 14:35:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SnfW6DLz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9914D22370 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:45850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxP3-0005D0-DS for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:35:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:32812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxO5-0003Xt-MP for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58446) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxO3-0006GM-Cr for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414052; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=h0heXC8AZt7eXzCvDvOmqsibMEQ+v+zzRIJ+pXZVz+w=; b=SnfW6DLzimiboYFpkHbCwITNlOfKh8+5ERITX0755I9IgkRws58AiLo8Yx72paXhz3D4oX x3r4LLhQ0TXDSRnLyna10erGIzI9xw3lIYxphjF1oM1ssV6DonDEqzcdbEzTXIOAWSM5Zi snyX7PaPIiWlNmdvVtszojVhHj97Stw= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-239-_hUDd3AXN1e7QxLnm-C4AA-1; Tue, 03 Nov 2020 09:34:09 -0500 X-MC-Unique: _hUDd3AXN1e7QxLnm-C4AA-1 Received: by mail-wr1-f72.google.com with SMTP id f11so7870378wro.15 for ; Tue, 03 Nov 2020 06:34:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=h0heXC8AZt7eXzCvDvOmqsibMEQ+v+zzRIJ+pXZVz+w=; b=SdzXda0yLqNEhi9OsaySQKa1JrOOrYV+B9M4MfaThmb5qBpAK/zn+EorJgkPkzheqW GPoAefsDQ1870Uz2Qv7ZkrdSmNVHXM4aOIz5W7Xwl54MsxsEiwXoVIPtskaOSkTESdl6 u42WNvWhjP/Cxd3zB0sA+TIaWKWEvm7R1whsGSKjv3zsozY4uoD08KZ3jOnv1FUqbo8O vaAUHWPEC4a7aC+i3GjJhK39nx8mHcHJRIWNRdBJ7UjETsGjmgmeSLWPIJ8xz0AXxb/9 z9vEQdJlDB0O/iPDjO8Faf/FTDJhpRv5wYh/YJ7NNmq2DIzlQDH0FfxE+O4F+Nx4QXFP nlRg== X-Gm-Message-State: AOAM530Snesd+FYWPqutElTHjcqmO45k7BhmFKR8kuW4cT0ijYc2YAvY R7y10K1LrYZRjzY19kqF3PEkpE9vl/+z3/5M5efC3xevb58Cve9AMAmHaSgKMF9C06yb2asYn5i wq9UR0UJiB9ECay8= X-Received: by 2002:a5d:67ca:: with SMTP id n10mr26149443wrw.209.1604414046431; Tue, 03 Nov 2020 06:34:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJyL3QmS3gSzmsOlZWcKr3WuwGKkkucHBx4sWePpFOv7fJXEKOGm8xa6ko1a1zBFjiLMGZN2nw== X-Received: by 2002:a5d:67ca:: with SMTP id n10mr26149419wrw.209.1604414046255; Tue, 03 Nov 2020 06:34:06 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id n4sm3083662wmi.32.2020.11.03.06.34.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:05 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:03 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 01/38] pc: comment style fixup Message-ID: <20201103142306.71782-2-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Eduardo Habkost , Chen Qun , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Fix up checkpatch comment style warnings. Signed-off-by: Michael S. Tsirkin Reviewed-by: Chen Qun --- hw/i386/pc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 5e6c0023e0..17b514d1da 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1149,10 +1149,11 @@ void pc_basic_device_init(struct PCMachineState *pcms, error_report("couldn't create HPET device"); exit(1); } - /* For pc-piix-*, hpet's intcap is always IRQ2. For pc-q35-1.7 - * and earlier, use IRQ2 for compat. Otherwise, use IRQ16~23, - * IRQ8 and IRQ2. - */ + /* + * For pc-piix-*, hpet's intcap is always IRQ2. For pc-q35-1.7 and + * earlier, use IRQ2 for compat. Otherwise, use IRQ16~23, IRQ8 and + * IRQ2. + */ uint8_t compat = object_property_get_uint(OBJECT(hpet), HPET_INTCAP, NULL); if (!compat) { From patchwork Tue Nov 3 14:34:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877787 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 C937592A for ; Tue, 3 Nov 2020 14:38:32 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6696C20757 for ; Tue, 3 Nov 2020 14:38:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aHIOgj5D" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6696C20757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxSB-0000eQ-Dq for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:38:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:32822) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxO5-0003YO-UG for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:44967) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxO3-0006GZ-Ca for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414053; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6mgCjhnq9faNGq2/uhjHeag8wnNyBtF7y3xz069QrTc=; b=aHIOgj5DZoLAIZQdgm/o4PWHzDSFX222NZc1Vxxp1l4RQ6/mFjsbIqLB3DAt8cWa3lmtyo Giw2j/v5Ys5MNX3HZjro0bZNuFRUwHvt0CV0ucUxQ5gJOEdjUTI6rLru9gW1I6WeAkt2Ay dbefNzqRO3NHRzHFnawkdTFAsbSJp9Y= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-22-g23F2Lr2PoimlQ9tO60FBQ-1; Tue, 03 Nov 2020 09:34:10 -0500 X-MC-Unique: g23F2Lr2PoimlQ9tO60FBQ-1 Received: by mail-wr1-f72.google.com with SMTP id t14so7948361wrs.2 for ; Tue, 03 Nov 2020 06:34:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6mgCjhnq9faNGq2/uhjHeag8wnNyBtF7y3xz069QrTc=; b=eYMv3R38W5SteB2NYZxvOqP3M/TyoZQ9vjkmCCd15HpvGRgxEvSTg5E1+rnUFyCxLs 3AKtaSIIDKgrobsmOGQw//65xg/seIPnlJPdU+DDUvz8atA/HxXhshLaMHKY0+oBnYKo Y0aMRFvSaoD9n6/J77X7QUzd2OcrUETahTnQHb82+5ayaKgTrGWAgTHUEJWsT3EaOkZz qcJROK60CuyFp4wwue93lYFVIV6UGH6zT6xjxmrC1WRX2RTlQ81oH5lsqGvoNLXgCJcz fTzvbsleiwjhNr5OUuPdQU5rb9oT9vpm3//IrXXSCQstF4BoB13q2sD5pSypAqPS14Ww OdeA== X-Gm-Message-State: AOAM531U5UIes6UNkwvY6mkXB536MaBUThyLkn2kLHIFw02RCz3WSUT1 OQwHpDekDrL4/C83P0klFzFKC6pDxstn/NwcSttJCO1Oip/OjmXkd81ZbxPbuDAmT6shPUMiBjq +7M3lKxxCkZ0zJDo= X-Received: by 2002:adf:a50e:: with SMTP id i14mr27051783wrb.121.1604414049026; Tue, 03 Nov 2020 06:34:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJyYebEpW0CRCDwXHbriaUKwfIRP1Wu+Gvg/Fxcx4ZXCw9WCH+2aaAMU76KMGD68VPlmGpY7KQ== X-Received: by 2002:adf:a50e:: with SMTP id i14mr27051752wrb.121.1604414048802; Tue, 03 Nov 2020 06:34:08 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id e3sm26581127wrn.32.2020.11.03.06.34.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:08 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:06 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 02/38] virtio-mem: Make sure "addr" is always multiples of the block size Message-ID: <20201103142306.71782-3-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Pankaj Gupta , David Hildenbrand , "Dr . David Alan Gilbert" , Wei Yang , Igor Mammedov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand The spec states: "The device MUST set addr, region_size, usable_region_size, plugged_size, requested_size to multiples of block_size." In some cases, we currently don't guarantee that for "addr": For example, when starting a VM with 4 GiB boot memory and a virtio-mem device with a block size of 2 GiB, "memaddr"/"addr" will be auto-assigned to 0x140000000 (5 GiB). We'll try to improve auto-assignment for memory devices next, to avoid bailing out in case memory device code selects a bad address. Note: The Linux driver doesn't support such big block sizes yet. Reviewed-by: Pankaj Gupta Fixes: 910b25766b33 ("virtio-mem: Paravirtualized memory hot(un)plug") Cc: "Michael S. Tsirkin" Cc: Wei Yang Cc: Dr. David Alan Gilbert Cc: Igor Mammedov Cc: Pankaj Gupta Signed-off-by: David Hildenbrand Message-Id: <20201008083029.9504-2-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-mem.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index 7c8ca9f28b..70200b4eac 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -449,6 +449,11 @@ static void virtio_mem_device_realize(DeviceState *dev, Error **errp) ")", VIRTIO_MEM_REQUESTED_SIZE_PROP, VIRTIO_MEM_BLOCK_SIZE_PROP, vmem->block_size); return; + } else if (!QEMU_IS_ALIGNED(vmem->addr, vmem->block_size)) { + error_setg(errp, "'%s' property has to be multiples of '%s' (0x%" PRIx64 + ")", VIRTIO_MEM_ADDR_PROP, VIRTIO_MEM_BLOCK_SIZE_PROP, + vmem->block_size); + return; } else if (!QEMU_IS_ALIGNED(memory_region_size(&vmem->memdev->mr), vmem->block_size)) { error_setg(errp, "'%s' property memdev size has to be multiples of" From patchwork Tue Nov 3 14:34:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877781 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 387D9921 for ; Tue, 3 Nov 2020 14:35:21 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DE67622370 for ; Tue, 3 Nov 2020 14:35:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Mk02C4Ee" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DE67622370 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46040 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxP5-0005Hz-JX for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:35:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:32850) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxO7-0003bc-BU for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54327) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxO4-0006HB-Hj for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414056; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=aiHSSZpWVmtRhYn18w/DUuKk+CQD6Uz5cJmFPDvNuls=; b=Mk02C4EeP3zhFv9KHp8cBLoVwpzs9fzOY8MkEHcv70nLumXR6ieXvAfQCb2y1dLQ1XVxnD RSA2w8Rn72y0dDJYtXxXRpPsARKs8RTbevhKcLO63btMboht9RmV7FUOAuBW3IBpXV7mwZ 9ShFXvni3kDAURCDOz7LM6Qs9b0koMY= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-459-cDcgaWI4NIWQ6XM2-hfbnQ-1; Tue, 03 Nov 2020 09:34:13 -0500 X-MC-Unique: cDcgaWI4NIWQ6XM2-hfbnQ-1 Received: by mail-wr1-f69.google.com with SMTP id h11so4934180wrq.20 for ; Tue, 03 Nov 2020 06:34:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=aiHSSZpWVmtRhYn18w/DUuKk+CQD6Uz5cJmFPDvNuls=; b=GrBRDN8gf0WsMudE4Jk7TTRxk1MsVWJY2t75uLeVBeKN7TaSSiV9slJh4925LI5Btl G2YxohWP6zvvytBqdnmktB0Qi2yHiHDfZF/5T4TfOQdx0UvMltEWSJL1RfgoslpTtqh+ EPZaidJre5RJ9Ro+usm3GrVk/qJ/aeG4xCVRl2uCETjI8UoenAPf6M7SdhgXWqrnLze7 U2eFPCShqbfyCsM2eoMuxwh5IdugiC5/4K3ewSI32WKnGzPNN6xtKq8+1dkU9kK3lw9N u39cyvSO74t+N2ygajeovKlt+EySQZTZiemdrqWAXuGg+C8TY4+2LsBGFHoXdLvfSPSe wDYg== X-Gm-Message-State: AOAM532P/7TTjME4ncx8MMJ1Tpjuv61FelcGnOTDyy2VNADHDAO73UZS W/kLv2VWmYEgyLrLTuvkgsUPy2t4VKhXpxCppxniaFUCYu6IsuupaduACBrV4kw5myDzdQsBGAF sTIID1FtbrJiL9Mw= X-Received: by 2002:adf:e490:: with SMTP id i16mr28287959wrm.178.1604414051702; Tue, 03 Nov 2020 06:34:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJzGGsk6g63+jKOJzWvHqq8KRyUMrgNFre8YYwivm/4PfpwZBS9rbGCeiuS8a4vsA9F7KGPibg== X-Received: by 2002:adf:e490:: with SMTP id i16mr28287939wrm.178.1604414051511; Tue, 03 Nov 2020 06:34:11 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id e5sm25074409wrw.93.2020.11.03.06.34.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:10 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:09 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 03/38] virtio-mem: Make sure "usable_region_size" is always multiples of the block size Message-ID: <20201103142306.71782-4-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Pankaj Gupta , David Hildenbrand , "Dr . David Alan Gilbert" , Wei Yang , Igor Mammedov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand The spec states: "The device MUST set addr, region_size, usable_region_size, plugged_size, requested_size to multiples of block_size." With block sizes > 256MB, we currently wouldn't guarantee that for the usable_region_size. Note that we cannot exceed the region_size, as we already enforce the alignment there properly. Fixes: 910b25766b33 ("virtio-mem: Paravirtualized memory hot(un)plug") Cc: "Michael S. Tsirkin" Cc: Wei Yang Cc: Dr. David Alan Gilbert Cc: Igor Mammedov Cc: Pankaj Gupta Signed-off-by: David Hildenbrand Message-Id: <20201008083029.9504-3-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-mem.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index 70200b4eac..461ac68ee8 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -227,6 +227,9 @@ static void virtio_mem_resize_usable_region(VirtIOMEM *vmem, uint64_t newsize = MIN(memory_region_size(&vmem->memdev->mr), requested_size + VIRTIO_MEM_USABLE_EXTENT); + /* The usable region size always has to be multiples of the block size. */ + newsize = QEMU_ALIGN_UP(newsize, vmem->block_size); + if (!requested_size) { newsize = 0; } From patchwork Tue Nov 3 14:34:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877785 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 0DB60921 for ; Tue, 3 Nov 2020 14:38:32 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B378B20757 for ; Tue, 3 Nov 2020 14:38:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZoYC/Aug" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B378B20757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54262 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxSA-0000ci-Ov for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:38:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:32884) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxO9-0003gV-Pg for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46530) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxO7-0006I3-Hr for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414058; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Bbvtq4HGVJ/wSfBQLsW+iRV9/tlIpRrNFHMItefyjY8=; b=ZoYC/Augcd60zEX7+5AS8IaodEn/ax73mvFgAuAmSKtIQb/F1p9zn6Ndkwakfp84sSXImN m+H8ir/e/wz2DUCSRgU57SPGxp7QSns1CSiaye3U1vc7MGnJKC96xEewKGE04oG46x5q8x VoWCnTmHrwY8rmi/B9jwV/NnWM9pNLM= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-14-pVRSu7dgOV679Zz_LOGKPw-1; Tue, 03 Nov 2020 09:34:15 -0500 X-MC-Unique: pVRSu7dgOV679Zz_LOGKPw-1 Received: by mail-wm1-f72.google.com with SMTP id z62so17493wmb.1 for ; Tue, 03 Nov 2020 06:34:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Bbvtq4HGVJ/wSfBQLsW+iRV9/tlIpRrNFHMItefyjY8=; b=DfBR7Nan2e19iMVEbncujb94vlJDs3SohyqRrlVO3zgMwKnTVywaXvk9ZaRP1CzANV S986MmMaG0S0W7TnVPZPKSQ6WxPmzs0SMvC1xKQUF7iaD3DkrmgS0pm1cdTyAtM1BaXC W1Ij/dhC5G3gZ3e7p/X4xS3IPTF+aMSJfeVKs/BTNzJOaVGV52XH57YX3coXIzINMhOV L2juKqUmElbgRV5JeK/+9XcOR/1IUU4SroVUu0Ox4oy7AcJOacPVE5vY6XMavBs7yLco Hirbniq8XqqCfKrs40k0RJrIdERTwW/MuaT6WDiLSiVKyT7OsMA15ypJtrqNQNMvqz8I 7xgQ== X-Gm-Message-State: AOAM533lPpAtBrz4D5raQmg5UAkUOJAfPkNoR93HsLPVAEMWlTqBWzS2 HgOluK1qDVgAyNi3FGRC5VOCEHpqBO/iPS0Z8slYJg5w2G2l4wFtcr/5YLMeBjgQY5juhMt9v9a uD/eoQ7O8umLyPvc= X-Received: by 2002:a5d:67c4:: with SMTP id n4mr26131073wrw.125.1604414054238; Tue, 03 Nov 2020 06:34:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJyY8oXxucAk0ZppGCT+iLOP/LB2FcfsJOnomIaYLCnDkvC/Ru4HBT+gMlonOeu77yVI4bSdXg== X-Received: by 2002:a5d:67c4:: with SMTP id n4mr26131055wrw.125.1604414054065; Tue, 03 Nov 2020 06:34:14 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id 30sm26156133wrs.84.2020.11.03.06.34.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:13 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:11 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 04/38] virtio-mem: Probe THP size to determine default block size Message-ID: <20201103142306.71782-5-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Pankaj Gupta , David Hildenbrand , "Dr . David Alan Gilbert" , Wei Yang , Igor Mammedov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand Let's allow a minimum block size of 1 MiB in all configurations. Select the default block size based on - The page size of the memory backend. - The THP size if the memory backend size corresponds to the real host page size. - The global minimum of 1 MiB. and warn if something smaller is configured by the user. VIRTIO_MEM only supports Linux (depends on LINUX), so we can probe the THP size unconditionally. For now we only support virtio-mem on x86-64 - there isn't a user-visible change (x86-64 only supports 2 MiB THP on the PMD level) - the default was, and will be 2 MiB. If we ever have THP on the PUD level (e.g., 1 GiB THP on x86-64), we expect it to be more transparent - e.g., to only optimize fully populated ranges unless explicitly told /configured otherwise (in contrast to PMD THP). Reviewed-by: Pankaj Gupta Cc: "Michael S. Tsirkin" Cc: Wei Yang Cc: Dr. David Alan Gilbert Cc: Igor Mammedov Cc: Pankaj Gupta Signed-off-by: David Hildenbrand Message-Id: <20201008083029.9504-4-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-mem.c | 105 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 4 deletions(-) diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index 461ac68ee8..655824ff81 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -33,10 +33,83 @@ #include "trace.h" /* - * Use QEMU_VMALLOC_ALIGN, so no THP will have to be split when unplugging - * memory (e.g., 2MB on x86_64). + * Let's not allow blocks smaller than 1 MiB, for example, to keep the tracking + * bitmap small. */ -#define VIRTIO_MEM_MIN_BLOCK_SIZE ((uint32_t)QEMU_VMALLOC_ALIGN) +#define VIRTIO_MEM_MIN_BLOCK_SIZE ((uint32_t)(1 * MiB)) + +#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || \ + defined(__powerpc64__) +#define VIRTIO_MEM_DEFAULT_THP_SIZE ((uint32_t)(2 * MiB)) +#else + /* fallback to 1 MiB (e.g., the THP size on s390x) */ +#define VIRTIO_MEM_DEFAULT_THP_SIZE VIRTIO_MEM_MIN_BLOCK_SIZE +#endif + +/* + * We want to have a reasonable default block size such that + * 1. We avoid splitting THPs when unplugging memory, which degrades + * performance. + * 2. We avoid placing THPs for plugged blocks that also cover unplugged + * blocks. + * + * The actual THP size might differ between Linux kernels, so we try to probe + * it. In the future (if we ever run into issues regarding 2.), we might want + * to disable THP in case we fail to properly probe the THP size, or if the + * block size is configured smaller than the THP size. + */ +static uint32_t thp_size; + +#define HPAGE_PMD_SIZE_PATH "/sys/kernel/mm/transparent_hugepage/hpage_pmd_size" +static uint32_t virtio_mem_thp_size(void) +{ + gchar *content = NULL; + const char *endptr; + uint64_t tmp; + + if (thp_size) { + return thp_size; + } + + /* + * Try to probe the actual THP size, fallback to (sane but eventually + * incorrect) default sizes. + */ + if (g_file_get_contents(HPAGE_PMD_SIZE_PATH, &content, NULL, NULL) && + !qemu_strtou64(content, &endptr, 0, &tmp) && + (!endptr || *endptr == '\n')) { + /* + * Sanity-check the value, if it's too big (e.g., aarch64 with 64k base + * pages) or weird, fallback to something smaller. + */ + if (!tmp || !is_power_of_2(tmp) || tmp > 16 * MiB) { + warn_report("Read unsupported THP size: %" PRIx64, tmp); + } else { + thp_size = tmp; + } + } + + if (!thp_size) { + thp_size = VIRTIO_MEM_DEFAULT_THP_SIZE; + warn_report("Could not detect THP size, falling back to %" PRIx64 + " MiB.", thp_size / MiB); + } + + g_free(content); + return thp_size; +} + +static uint64_t virtio_mem_default_block_size(RAMBlock *rb) +{ + const uint64_t page_size = qemu_ram_pagesize(rb); + + /* We can have hugetlbfs with a page size smaller than the THP size. */ + if (page_size == qemu_real_host_page_size) { + return MAX(page_size, virtio_mem_thp_size()); + } + return MAX(page_size, VIRTIO_MEM_MIN_BLOCK_SIZE); +} + /* * Size the usable region bigger than the requested size if possible. Esp. * Linux guests will only add (aligned) memory blocks in case they fully @@ -443,10 +516,23 @@ static void virtio_mem_device_realize(DeviceState *dev, Error **errp) rb = vmem->memdev->mr.ram_block; page_size = qemu_ram_pagesize(rb); + /* + * If the block size wasn't configured by the user, use a sane default. This + * allows using hugetlbfs backends of any page size without manual + * intervention. + */ + if (!vmem->block_size) { + vmem->block_size = virtio_mem_default_block_size(rb); + } + if (vmem->block_size < page_size) { error_setg(errp, "'%s' property has to be at least the page size (0x%" PRIx64 ")", VIRTIO_MEM_BLOCK_SIZE_PROP, page_size); return; + } else if (vmem->block_size < virtio_mem_default_block_size(rb)) { + warn_report("'%s' property is smaller than the default block size (%" + PRIx64 " MiB)", VIRTIO_MEM_BLOCK_SIZE_PROP, + virtio_mem_default_block_size(rb) / MiB); } else if (!QEMU_IS_ALIGNED(vmem->requested_size, vmem->block_size)) { error_setg(errp, "'%s' property has to be multiples of '%s' (0x%" PRIx64 ")", VIRTIO_MEM_REQUESTED_SIZE_PROP, @@ -742,6 +828,18 @@ static void virtio_mem_get_block_size(Object *obj, Visitor *v, const char *name, const VirtIOMEM *vmem = VIRTIO_MEM(obj); uint64_t value = vmem->block_size; + /* + * If not configured by the user (and we're not realized yet), use the + * default block size we would use with the current memory backend. + */ + if (!value) { + if (vmem->memdev && memory_region_is_ram(&vmem->memdev->mr)) { + value = virtio_mem_default_block_size(vmem->memdev->mr.ram_block); + } else { + value = virtio_mem_thp_size(); + } + } + visit_type_size(v, name, &value, errp); } @@ -821,7 +919,6 @@ static void virtio_mem_instance_init(Object *obj) { VirtIOMEM *vmem = VIRTIO_MEM(obj); - vmem->block_size = VIRTIO_MEM_MIN_BLOCK_SIZE; notifier_list_init(&vmem->size_change_notifiers); vmem->precopy_notifier.notify = virtio_mem_precopy_notify; From patchwork Tue Nov 3 14:34:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877789 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 BCDF992A for ; Tue, 3 Nov 2020 14:38:35 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5FAA820757 for ; Tue, 3 Nov 2020 14:38:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gMJ1BldB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5FAA820757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxSD-0000kg-VW for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:38:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:32902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxOB-0003l4-Mo for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36861) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxO9-0006JR-PU for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414061; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Sdg1XQq2wWnBWKWHjU6hAJQnpSiiinwLqOwmCIMoYHk=; b=gMJ1BldBcONnwywErmCJlwpKjGPSpbZtDpXer1iLUa/s646OZkpeMqiV1bx9meyDhOjInE OuWzUqPRGOzfCSKLBymUUhb1NpbQff3ueYUppODW2LiYtaZaPJWdc8cOL3h1eSAQVNOtZ/ /cjaIOQsJKHxWt1yV6bc5qrshTTdKD4= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-269-dfQUqnVUOH-w1n5bhIRxqA-1; Tue, 03 Nov 2020 09:34:18 -0500 X-MC-Unique: dfQUqnVUOH-w1n5bhIRxqA-1 Received: by mail-wr1-f72.google.com with SMTP id w6so272045wrk.1 for ; Tue, 03 Nov 2020 06:34:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Sdg1XQq2wWnBWKWHjU6hAJQnpSiiinwLqOwmCIMoYHk=; b=SHWmKLzhpm7NhAHVVoGVTXWwZ+i++yuf2TDfuAmjYC1odWvYG0XwnzNHejgqRg/1n6 NTJ8VJZAtacdCeWTYX0ehvRlLjKIXCZT4goay+Oy1o1GvtaK08g11qR/Ex7K1YNkclnX bdNl3HZ0civgWC75/IUg85S+A+J5gFAVtdD4xYEHiPmLqxGOpRz49jCOylEfajY+VzuO a4ALWGDyEFEJkhgU7Yj0xHwA8cYWUIe8QM6CARZaCzpiE+u1/psIr5UqdlVsH5Ru155o DMG4b777XpPOSQNCtADByaVpxY+Y7iMbVo2esagL23hF2JrVcWkY/DpOU8GsrOHW7Kqa iosA== X-Gm-Message-State: AOAM531gWATwrF/kos2p7sWqBLb2P/MK3hZgeRkbsmAyiPfbrxupr6FR Lagl0rM75c/OfkajbxmPFwOSNSpyDQGqD1E5DQBp7NJg8V8FPK8d/eDj3+abAIATLbucuxFhren T8wxgEV2UIy0nXpg= X-Received: by 2002:a7b:c101:: with SMTP id w1mr48925wmi.170.1604414056797; Tue, 03 Nov 2020 06:34:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/2WkFi7ZaRYoe3SsHv9nM8ohAUKmhhnQrFY8zjY8vaa7LxsI/6TTm/6ia1kLf7Vos59J/wg== X-Received: by 2002:a7b:c101:: with SMTP id w1mr48913wmi.170.1604414056652; Tue, 03 Nov 2020 06:34:16 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id e2sm27690990wrr.85.2020.11.03.06.34.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:16 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:14 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 05/38] memory-device: Support big alignment requirements Message-ID: <20201103142306.71782-6-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Pankaj Gupta , David Hildenbrand , "Dr . David Alan Gilbert" , Wei Yang , Igor Mammedov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand Let's warn instead of bailing out - the worst thing that can happen is that we'll fail hot/coldplug later. The user got warned, and this should be rare. This will be necessary for memory devices with rather big (user-defined) alignment requirements - say a virtio-mem device with a 2G block size - which will become important, for example, when supporting vfio in the future. Reviewed-by: Pankaj Gupta Cc: "Michael S. Tsirkin" Cc: Wei Yang Cc: Dr. David Alan Gilbert Cc: Igor Mammedov Cc: Pankaj Gupta Signed-off-by: David Hildenbrand Message-Id: <20201008083029.9504-5-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/mem/memory-device.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 4bc9cf0917..8a736f1a26 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -119,9 +119,10 @@ static uint64_t memory_device_get_free_addr(MachineState *ms, /* start of address space indicates the maximum alignment we expect */ if (!QEMU_IS_ALIGNED(range_lob(&as), align)) { - error_setg(errp, "the alignment (0x%" PRIx64 ") is not supported", - align); - return 0; + warn_report("the alignment (0x%" PRIx64 ") exceeds the expected" + " maximum alignment, memory will get fragmented and not" + " all 'maxmem' might be usable for memory devices.", + align); } memory_device_check_addable(ms, size, &err); @@ -151,7 +152,7 @@ static uint64_t memory_device_get_free_addr(MachineState *ms, return 0; } } else { - if (range_init(&new, range_lob(&as), size)) { + if (range_init(&new, QEMU_ALIGN_UP(range_lob(&as), align), size)) { error_setg(errp, "can't add memory device, device too big"); return 0; } From patchwork Tue Nov 3 14:34:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877801 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 0878992A for ; Tue, 3 Nov 2020 14:41:35 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 88A7E223AC for ; Tue, 3 Nov 2020 14:41:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QUCF3kR8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 88A7E223AC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxV7-0004MV-7Z for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:41:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:32936) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxOF-0003tn-N4 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:34122) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxOD-0006Kf-Q3 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414064; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=73Mpz3vICh9QEBEOeL5uEWGSphcZBjM+o5MkFyzWxeI=; b=QUCF3kR8X6dV29s5VM/SJpo1HzCsGUOitzcppHIwgqLFC6lR+Tvnl/ddHcncI6wZcTUV5k kzTnEpWMT34BGdeJStwX7w+9tdvQ02vy5bdJhRvFLGI+aVScdwFoYdC0IkY/StwbU3zijk JYQfKNS/JeyuNFIBJ7rQlaMKtuHVFQU= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-236-izI3nhs_OUmQKGHTzrZ9vw-1; Tue, 03 Nov 2020 09:34:22 -0500 X-MC-Unique: izI3nhs_OUmQKGHTzrZ9vw-1 Received: by mail-wr1-f70.google.com with SMTP id m20so7902707wrb.21 for ; Tue, 03 Nov 2020 06:34:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=73Mpz3vICh9QEBEOeL5uEWGSphcZBjM+o5MkFyzWxeI=; b=DTCrUFu9iwokP0jBmqKLfMyi4c55Ch063ZL5IUBFD1lC+t8SEWOZ3f6qVTiUJeH+2y vp2z8gWykZCX/HtiBRF44X4eqlggIEf5lcdDqPmLF7WJG1wUug+GQCOca7qPKvf2rle0 JErtzOOqOLVbvCETKufV0XjIEPfAu7TsL14dlL7ADV7dnG8s15dO5ldvRyBWneThuSzu 12i+z/qEjnVkj7V0R1brlblUHgNqqAZ5mTBp1A2euh4zDOl0hpmQfrMWgbnQSbwdjM4L noxneSjmgNvhx7clQJYTYR92qMyI36EJJxlY4xFk74vyI6Ag8aPeI4dzKLf/92/TcqDp ZciA== X-Gm-Message-State: AOAM532b9PveQ7E3Q6wUAZggc6auWYw7EYSA+E5GDTrF7CZYxNvw4Ssk rMYnjylcmQHLRlL/M76INVsUbTfH6sz9Q6rRZXdoCWleRq+7g5JhHPxO4POuO69ygZExo3/gfE1 SkSZYEOsVtfXFeIc= X-Received: by 2002:a1c:6355:: with SMTP id x82mr2996wmb.177.1604414059400; Tue, 03 Nov 2020 06:34:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJwwehOhhxX92t6WHcMnh72YlZ6mLyzC7XCcu6K7unY+bgsEConpgt0c4SXjzYSbtIPxQcC3Jg== X-Received: by 2002:a1c:6355:: with SMTP id x82mr2976wmb.177.1604414059191; Tue, 03 Nov 2020 06:34:19 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id y185sm3040543wmb.29.2020.11.03.06.34.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:18 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:16 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 06/38] memory-device: Add get_min_alignment() callback Message-ID: <20201103142306.71782-7-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Pankaj Gupta , David Hildenbrand , "Dr . David Alan Gilbert" , Wei Yang , Igor Mammedov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand Add a callback that can be used to express additional alignment requirements (exceeding the ones from the memory region). Will be used by virtio-mem to express special alignment requirements due to manually configured, big block sizes (e.g., 1GB with an ordinary memory-backend-ram). This avoids failing later when realizing, because auto-detection wasn't able to assign a properly aligned address. Reviewed-by: Pankaj Gupta Cc: "Michael S. Tsirkin" Cc: Wei Yang Cc: Dr. David Alan Gilbert Cc: Igor Mammedov Cc: Pankaj Gupta Signed-off-by: David Hildenbrand Message-Id: <20201008083029.9504-6-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/mem/memory-device.h | 10 ++++++++++ hw/mem/memory-device.c | 11 +++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 30d7e99f52..48d2611fc5 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -88,6 +88,16 @@ struct MemoryDeviceClass { */ MemoryRegion *(*get_memory_region)(MemoryDeviceState *md, Error **errp); + /* + * Optional: Return the desired minimum alignment of the device in guest + * physical address space. The final alignment is computed based on this + * alignment and the alignment requirements of the memory region. + * + * Called when plugging the memory device to detect the required alignment + * during address assignment. + */ + uint64_t (*get_min_alignment)(const MemoryDeviceState *md); + /* * Translate the memory device into #MemoryDeviceInfo. */ diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 8a736f1a26..cf0627fd01 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -259,7 +259,7 @@ void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms, { const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md); Error *local_err = NULL; - uint64_t addr, align; + uint64_t addr, align = 0; MemoryRegion *mr; mr = mdc->get_memory_region(md, &local_err); @@ -267,7 +267,14 @@ void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms, goto out; } - align = legacy_align ? *legacy_align : memory_region_get_alignment(mr); + if (legacy_align) { + align = *legacy_align; + } else { + if (mdc->get_min_alignment) { + align = mdc->get_min_alignment(md); + } + align = MAX(align, memory_region_get_alignment(mr)); + } addr = mdc->get_addr(md); addr = memory_device_get_free_addr(ms, !addr ? NULL : &addr, align, memory_region_size(mr), &local_err); From patchwork Tue Nov 3 14:34:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877803 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 92B0A1130 for ; Tue, 3 Nov 2020 14:41:35 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 36A0A22456 for ; Tue, 3 Nov 2020 14:41:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NCkyvIEl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 36A0A22456 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxV8-0004O9-2K for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:41:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:32946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxOH-0003wN-0I for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:35490) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxOF-0006LJ-0u for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414065; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=NLAI6E52qR6iiwo+p5ybiNDvz6sVMxaw+nStvrHSOQ4=; b=NCkyvIEl972LcLfv05wlswi6bSCnEaFn5kBib2usKg1nS4/S7Mu+vC0JPqOHqJTMbZ02D8 KL6/vPIXosnw5TOL8bFvu1VaTPQfp9nGw24RwHtax9bnyp6gC3UM/DXRP66rtLKc/Pbu3r kY9rzrn0KcL30UfI+FPxvjtPuIrdxU8= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-16-TMIolHGuOZqm6-DePovCmw-1; Tue, 03 Nov 2020 09:34:23 -0500 X-MC-Unique: TMIolHGuOZqm6-DePovCmw-1 Received: by mail-wm1-f72.google.com with SMTP id o19so4682259wme.2 for ; Tue, 03 Nov 2020 06:34:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=NLAI6E52qR6iiwo+p5ybiNDvz6sVMxaw+nStvrHSOQ4=; b=QgvY6/EqbszDxShRIU/yyxNddWrSxW16sIGpnububQnRd106azaH2cf+SzztFldpfQ QBjbGJFEQaJgxRQ0s4sqZ+47mh41p2M+Ykk5Hx14Bwa0cRzGgtB7YvKoGFn8C3HuNUIo 9JYDcb96MxZq0T/7O1Z9J/+9AUn4d5KBhhtVfJNV7yV3wn7w3UvNcJUaGZmeoYzVVsbO pQCDTr2pKZTk9fORdbtfbXvBQ4ZoxCPcnn72uclGSCLCaklvIS8azgIs2O9h37PuvXqL 8Qg2bNlMtStp9KiGjKE6xCmmedIuThC4O8YaoTKfx3Kpjt61S3J6KOutJmsMVf9NcEnG kd1w== X-Gm-Message-State: AOAM53125iUs71aI/GKTvufD4ITkqokdiv+XcrIvHI7loK4/8AmDlJ+C E5uz5Evm4xPhMDF4seP9reF2MHJkH2t4Y5bqdZ8q9yutBeL49cTSSL1MzrbkGHcu2uPNfglZYrn TIlvNE2WAdgJULuY= X-Received: by 2002:a1c:4d05:: with SMTP id o5mr64142wmh.94.1604414061893; Tue, 03 Nov 2020 06:34:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJwCHAjnecwNLODgebl5fEP+/5wgCz6fGh5Lm8ODATab2hmtp2PDZ+MoutMgpzpfqO3rpATXhg== X-Received: by 2002:a1c:4d05:: with SMTP id o5mr64135wmh.94.1604414061753; Tue, 03 Nov 2020 06:34:21 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id 205sm3270214wme.38.2020.11.03.06.34.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:21 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:19 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 07/38] virito-mem: Implement get_min_alignment() Message-ID: <20201103142306.71782-8-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Pankaj Gupta , David Hildenbrand , "Dr . David Alan Gilbert" , Wei Yang , Igor Mammedov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand The block size determines the alignment requirements. Implement get_min_alignment() of the TYPE_MEMORY_DEVICE interface. This allows auto-assignment of a properly aligned address in guest physical address space. For example, when specifying a 2GB block size for a virtio-mem device with 10GB with a memory setup "-m 4G, 20G", we'll no longer fail when realizing. Reviewed-by: Pankaj Gupta Cc: "Michael S. Tsirkin" Cc: Wei Yang Cc: Dr. David Alan Gilbert Cc: Igor Mammedov Cc: Pankaj Gupta Signed-off-by: David Hildenbrand Message-Id: <20201008083029.9504-7-david@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-mem-pci.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/virtio/virtio-mem-pci.c b/hw/virtio/virtio-mem-pci.c index 913f4a3326..fa5395cd88 100644 --- a/hw/virtio/virtio-mem-pci.c +++ b/hw/virtio/virtio-mem-pci.c @@ -76,6 +76,12 @@ static void virtio_mem_pci_fill_device_info(const MemoryDeviceState *md, info->type = MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM; } +static uint64_t virtio_mem_pci_get_min_alignment(const MemoryDeviceState *md) +{ + return object_property_get_uint(OBJECT(md), VIRTIO_MEM_BLOCK_SIZE_PROP, + &error_abort); +} + static void virtio_mem_pci_size_change_notify(Notifier *notifier, void *data) { VirtIOMEMPCI *pci_mem = container_of(notifier, VirtIOMEMPCI, @@ -110,6 +116,7 @@ static void virtio_mem_pci_class_init(ObjectClass *klass, void *data) mdc->get_plugged_size = virtio_mem_pci_get_plugged_size; mdc->get_memory_region = virtio_mem_pci_get_memory_region; mdc->fill_device_info = virtio_mem_pci_fill_device_info; + mdc->get_min_alignment = virtio_mem_pci_get_min_alignment; } static void virtio_mem_pci_instance_init(Object *obj) From patchwork Tue Nov 3 14:34:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877811 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 43ED6921 for ; Tue, 3 Nov 2020 14:44:08 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E9E41223C7 for ; Tue, 3 Nov 2020 14:44:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MiuIpIjM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E9E41223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:43224 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxXb-00080F-0J for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:44:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:32994) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxOJ-00041t-JA for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:33116) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxOH-0006Mg-Gp for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ghKT3iuLd9VX4UT4KJCLl/E2c6yAP84MyPy0077dPys=; b=MiuIpIjMbksMJL97i251swKGGsp9szitKTBQjWltan5/Pbo/9G3mPzv5MWFCauMA8EZHzU h0Muzb9bTLwNU2kckS6cQAQdRR8UB4AL20UHVPLpLVa/NNIpPC1oVOE65r7JhEJ+JukA/f xzFw346ASFj6BYVZ/BZK3mUfsiibSYg= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-286-FhpUoh2xPZy-iSCE4EK8SQ-1; Tue, 03 Nov 2020 09:34:26 -0500 X-MC-Unique: FhpUoh2xPZy-iSCE4EK8SQ-1 Received: by mail-wr1-f69.google.com with SMTP id 33so7834117wrf.22 for ; Tue, 03 Nov 2020 06:34:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ghKT3iuLd9VX4UT4KJCLl/E2c6yAP84MyPy0077dPys=; b=f+iF2nVGPjah+tUVqXwkWYyaMKrQwSqCsvRs2r/Odsn+4lA9zsb0BZfTzWjOP2xVD9 CYuQeiC8zQsOTvsXseZJIF3ac9kQHxEIkj6SxDEFUuiqROQ1hykkwEDaBy7b/o77aNPM qXTmXDzedvVl61AQhoIVgFz4zyoa45Ra65+f0tACKeqXX3LcJGsOfWj4vAPNoaZBwWn7 t4CjHCgrH5pghdNigIKghMwOXRVX6va/03dU7V0BXggS4XcY9hbPh1J8/sPp/oF7Exsz IQRzt3ukYOBVqmswTKMsQIhFAG01mDN8uI077J+Xw9Ww1WYcGtfRvG1NAdQZj6C6teYD PtCA== X-Gm-Message-State: AOAM530tLzqWrUGyda9PKEiqaYOJaQWSsipdlJhqfnuzN0BxWYci8IWz MPH3ceW8RCdUdui6BJUE9BVPpsk5oTiwY3+rbTzBt6887KSa37StTxaHelQwVbg4zlkxtSRjahi mi/OnRufCd3WhK8k= X-Received: by 2002:a5d:494c:: with SMTP id r12mr26072104wrs.406.1604414064444; Tue, 03 Nov 2020 06:34:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJxrmGx5g9IBI95ZFOgXtiMs//cfZsIX6/fqO3WuVzeZ256GGIRx+Wxjzk+vnENpewVrxN5hOA== X-Received: by 2002:a5d:494c:: with SMTP id r12mr26072090wrs.406.1604414064258; Tue, 03 Nov 2020 06:34:24 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id e25sm27507660wra.71.2020.11.03.06.34.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:23 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:22 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 08/38] hw/acpi : Don't use '#' flag of printf format Message-ID: <20201103142306.71782-9-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Igor Mammedov , Kai Deng , Xiao Guangrong , Xinhao Zhang Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Xinhao Zhang Fix code style. Don't use '#' flag of printf format ('%#') in format strings, use '0x' prefix instead Signed-off-by: Xinhao Zhang Signed-off-by: Kai Deng Message-Id: <20201103102634.273021-1-zhangxinhao1@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/acpi/nvdimm.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c index 8f7cc16add..8ad5516142 100644 --- a/hw/acpi/nvdimm.c +++ b/hw/acpi/nvdimm.c @@ -556,7 +556,7 @@ static void nvdimm_dsm_func_read_fit(NVDIMMState *state, NvdimmDsmIn *in, fit = fit_buf->fit; - nvdimm_debug("Read FIT: offset %#x FIT size %#x Dirty %s.\n", + nvdimm_debug("Read FIT: offset 0x%x FIT size 0x%x Dirty %s.\n", read_fit->offset, fit->len, fit_buf->dirty ? "Yes" : "No"); if (read_fit->offset > fit->len) { @@ -664,7 +664,7 @@ static void nvdimm_dsm_label_size(NVDIMMDevice *nvdimm, hwaddr dsm_mem_addr) label_size = nvdimm->label_size; mxfer = nvdimm_get_max_xfer_label_size(); - nvdimm_debug("label_size %#x, max_xfer %#x.\n", label_size, mxfer); + nvdimm_debug("label_size 0x%x, max_xfer 0x%x.\n", label_size, mxfer); label_size_out.func_ret_status = cpu_to_le32(NVDIMM_DSM_RET_STATUS_SUCCESS); label_size_out.label_size = cpu_to_le32(label_size); @@ -680,19 +680,19 @@ static uint32_t nvdimm_rw_label_data_check(NVDIMMDevice *nvdimm, uint32_t ret = NVDIMM_DSM_RET_STATUS_INVALID; if (offset + length < offset) { - nvdimm_debug("offset %#x + length %#x is overflow.\n", offset, + nvdimm_debug("offset 0x%x + length 0x%x is overflow.\n", offset, length); return ret; } if (nvdimm->label_size < offset + length) { - nvdimm_debug("position %#x is beyond label data (len = %" PRIx64 ").\n", + nvdimm_debug("position 0x%x is beyond label data (len = %" PRIx64 ").\n", offset + length, nvdimm->label_size); return ret; } if (length > nvdimm_get_max_xfer_label_size()) { - nvdimm_debug("length (%#x) is larger than max_xfer (%#x).\n", + nvdimm_debug("length (0x%x) is larger than max_xfer (0x%x).\n", length, nvdimm_get_max_xfer_label_size()); return ret; } @@ -716,7 +716,7 @@ static void nvdimm_dsm_get_label_data(NVDIMMDevice *nvdimm, NvdimmDsmIn *in, get_label_data->offset = le32_to_cpu(get_label_data->offset); get_label_data->length = le32_to_cpu(get_label_data->length); - nvdimm_debug("Read Label Data: offset %#x length %#x.\n", + nvdimm_debug("Read Label Data: offset 0x%x length 0x%x.\n", get_label_data->offset, get_label_data->length); status = nvdimm_rw_label_data_check(nvdimm, get_label_data->offset, @@ -755,7 +755,7 @@ static void nvdimm_dsm_set_label_data(NVDIMMDevice *nvdimm, NvdimmDsmIn *in, set_label_data->offset = le32_to_cpu(set_label_data->offset); set_label_data->length = le32_to_cpu(set_label_data->length); - nvdimm_debug("Write Label Data: offset %#x length %#x.\n", + nvdimm_debug("Write Label Data: offset 0x%x length 0x%x.\n", set_label_data->offset, set_label_data->length); status = nvdimm_rw_label_data_check(nvdimm, set_label_data->offset, @@ -838,7 +838,7 @@ nvdimm_dsm_write(void *opaque, hwaddr addr, uint64_t val, unsigned size) NvdimmDsmIn *in; hwaddr dsm_mem_addr = val; - nvdimm_debug("dsm memory address %#" HWADDR_PRIx ".\n", dsm_mem_addr); + nvdimm_debug("dsm memory address 0x%" HWADDR_PRIx ".\n", dsm_mem_addr); /* * The DSM memory is mapped to guest address space so an evil guest @@ -852,11 +852,11 @@ nvdimm_dsm_write(void *opaque, hwaddr addr, uint64_t val, unsigned size) in->function = le32_to_cpu(in->function); in->handle = le32_to_cpu(in->handle); - nvdimm_debug("Revision %#x Handler %#x Function %#x.\n", in->revision, + nvdimm_debug("Revision 0x%x Handler 0x%x Function 0x%x.\n", in->revision, in->handle, in->function); if (in->revision != 0x1 /* Currently we only support DSM Spec Rev1. */) { - nvdimm_debug("Revision %#x is not supported, expect %#x.\n", + nvdimm_debug("Revision 0x%x is not supported, expect 0x%x.\n", in->revision, 0x1); nvdimm_dsm_no_payload(NVDIMM_DSM_RET_STATUS_UNSUPPORT, dsm_mem_addr); goto exit; From patchwork Tue Nov 3 14:34:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877783 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 8B1AA92A for ; Tue, 3 Nov 2020 14:36:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2A51B22370 for ; Tue, 3 Nov 2020 14:36:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WsKy1whj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2A51B22370 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:47968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxPv-0006Hk-3n for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:36:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33068) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxOP-0004F8-Sa for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:38213) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxOM-0006OY-Fg for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414073; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=g3L/0LWUS5AALGZ/Ad9jPepioK718BBOf2ilNljz6+w=; b=WsKy1whjvJWwNPoxucCKTu/tW3r1rPkkNY1WISvR0TjJxsOWgGp08DTJTGNe0x4/BXfmLP fCt0BAlNSnQzXQcmnfa0fcoBfw16yrSea1T8lMSsvNQcQVgZJFnyzqhbv93/fA9YaoqV/u lBoGvEBjn7kVPyeaiNsMDqS0y5pUvGg= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-252-LMe-c61SNhKAn0CXVvg4aw-1; Tue, 03 Nov 2020 09:34:29 -0500 X-MC-Unique: LMe-c61SNhKAn0CXVvg4aw-1 Received: by mail-wm1-f70.google.com with SMTP id y187so1888582wmy.3 for ; Tue, 03 Nov 2020 06:34:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=g3L/0LWUS5AALGZ/Ad9jPepioK718BBOf2ilNljz6+w=; b=a3KycwMu7HfIKNnpwweD0jpdefmZLUfkhOxJh4HsBUu5s0WOsWUrTNhtJwFAM5v/VF kDjiI4RCQ4SSr/gdoMLEtKd6ISrHTy7rvGbIqKWKHM60QgSivObaLZaf5Ym8r58TBYxZ JKhmfEPMCgRpeZv/7Yj3uX+6wwXMg4EMofUNHmhwJWyDfvTU1jzy2cBwlaMjzFPs3Vps mOlHAqkWu1VLZspaCClKx4q/gP8ym+3W2PULm+6Tp0SpRJ5CpNmzVJ4pJLJzgFL99Iad uOmJi+Z+1uq5ni7ZzShkhp/fgflNoanGnBj5sTgN0gpPoRoYNOHikAQdnO/geBNyOcY/ wCvQ== X-Gm-Message-State: AOAM533LjyEKBIT0H9ZQTZH8+XVnKZK7w5Beq/aW3uBYQKDHu3ta4FZO d/KojSuXFPB/EcurSQzP5l3W0tZGVAa5w0PGADZjCBgPmXB2iPkWsf+wXtHJC/+bh+Fzu6k5rSD 5V7oA8kGCBRSooPk= X-Received: by 2002:a05:6000:108:: with SMTP id o8mr26457103wrx.256.1604414067347; Tue, 03 Nov 2020 06:34:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJyzSX/BUKuCoZCXCSXiOIKmDTuUBN7wgJ59kwHKuKPbfsh6Da4DdlXhsdawlV58XHuyAub7nw== X-Received: by 2002:a05:6000:108:: with SMTP id o8mr26457050wrx.256.1604414066730; Tue, 03 Nov 2020 06:34:26 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id d8sm2956384wmb.11.2020.11.03.06.34.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:26 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:24 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 09/38] hw/acpi : add space before the open parenthesis '(' Message-ID: <20201103142306.71782-10-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Igor Mammedov , Kai Deng , Xinhao Zhang Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Xinhao Zhang Fix code style. Space required before the open parenthesis '('. Signed-off-by: Xinhao Zhang Signed-off-by: Kai Deng Message-Id: <20201103102634.273021-2-zhangxinhao1@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/acpi/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/acpi/core.c b/hw/acpi/core.c index ade9158cbf..2c0c83221f 100644 --- a/hw/acpi/core.c +++ b/hw/acpi/core.c @@ -558,7 +558,7 @@ static void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val) if (val & ACPI_BITMASK_SLEEP_ENABLE) { /* change suspend type */ uint16_t sus_typ = (val >> 10) & 7; - switch(sus_typ) { + switch (sus_typ) { case 0: /* soft power off */ qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); break; From patchwork Tue Nov 3 14:34:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877809 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 89F69921 for ; Tue, 3 Nov 2020 14:44:06 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 359A4223C7 for ; Tue, 3 Nov 2020 14:44:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="J4MvPffN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 359A4223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:43054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxXZ-0007wD-Ab for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:44:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxOO-0004DB-Tw for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:20203) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxON-0006Oc-1z for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414074; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kxx7KBtrm7vYLNNi8ILRStjcIKIqdM/KqZjCc2FDurE=; b=J4MvPffNBLz/4rgzk61x0Yb/YmZe7Hhg5RZei5S/yiLNH14JkfUsy1h3M03EYECVJBvgXe 9h05OL93jOthUV87kCdlLHnfL4VyD5YG6JxXtw9GZT7/a4wYwfLCVH/Tj0DgLjFX8sT1RZ //5EV84IrzL3zDOfbb+Ab2onQGF64JE= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-398-HR66kw6DOxGNHnWlmCdMLA-1; Tue, 03 Nov 2020 09:34:31 -0500 X-MC-Unique: HR66kw6DOxGNHnWlmCdMLA-1 Received: by mail-wm1-f70.google.com with SMTP id l16so2703610wmh.1 for ; Tue, 03 Nov 2020 06:34:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=kxx7KBtrm7vYLNNi8ILRStjcIKIqdM/KqZjCc2FDurE=; b=DWBro23smbQnvjG98pEAiN1Es9gVNeR0jfBU6FGE32EuhCC8p2b7zY4UlvW0KVxLjn hNMCQBxt4xDJFv4gXSOmVRjsYf8OSoY9dL3SwYF54w/upX6DICAnAUXUJ+BYZFsUGZ5S k7cjZwJZ7sI01QbxWudjx+zgFW57p2z4/u0pcApUUz+HoNWXEe1r6Q+d//E7FEUuj9tx lS+WTftknubQDPgp78LYPkkUrSbbVYuQyxx0mcRJsU0Ppxxn8BM4TQoUuSwvrsHoLiMa A0guPsHfv6eGWBK6c1m5neBLCgg3aoWGsP91OrmmH94+Pgm/U6nMYWMoWE61KO9Ai+d6 z7lg== X-Gm-Message-State: AOAM532C+sBxTVxetUBpAvl/JD7zlA41JiOhfvutmDHDA8yru5F/k1vS 5ZnAiuyC4RGcD5N6R/cMS6p3l3w81I6yxrWHzyiEGtw/7eKJmpK6A6T0g4tD9Oh+G4lrFnEKiD8 F4sQt7eTCmL652Jk= X-Received: by 2002:a1c:98ce:: with SMTP id a197mr61569wme.116.1604414070366; Tue, 03 Nov 2020 06:34:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJyKVunZqn0Mb1UMJ7Mlm5F/4ar5hjxQx1IXTL681GXBN2N0ONneg14ArRXb85LDPM4U6gNF2g== X-Received: by 2002:a1c:98ce:: with SMTP id a197mr61550wme.116.1604414070226; Tue, 03 Nov 2020 06:34:30 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id j127sm3336605wma.31.2020.11.03.06.34.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:28 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:27 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 10/38] hw/acpi : add spaces around operator Message-ID: <20201103142306.71782-11-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Igor Mammedov , Kai Deng , Xinhao Zhang Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Xinhao Zhang Fix code style. Operator needs spaces both sides. Signed-off-by: Xinhao Zhang Signed-off-by: Kai Deng Message-Id: <20201103102634.273021-3-zhangxinhao1@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/acpi/pcihp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c index 32ae8b2c0a..17c32e0ffd 100644 --- a/hw/acpi/pcihp.c +++ b/hw/acpi/pcihp.c @@ -400,7 +400,7 @@ void acpi_pcihp_init(Object *owner, AcpiPciHpState *s, PCIBus *root_bus, s->io_len = ACPI_PCIHP_SIZE; s->io_base = ACPI_PCIHP_ADDR; - s->root= root_bus; + s->root = root_bus; s->legacy_piix = !bridges_enabled; memory_region_init_io(&s->io, owner, &acpi_pcihp_io_ops, s, From patchwork Tue Nov 3 14:34:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877795 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 E266692A for ; Tue, 3 Nov 2020 14:39:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9E7BC22370 for ; Tue, 3 Nov 2020 14:39:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fQnzIRwR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9E7BC22370 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:57450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxT0-0001zr-MA for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:39:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33132) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxOY-0004RZ-SN for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:25598) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxOX-0006Rh-8c for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414084; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4t5NY5zyTFxf5JdPvPR+dRhfn/ny8MSoW1vs+UM3VkI=; b=fQnzIRwRyw0v3Ytg9G61HLlIlcx3wL+n/5u8DD5zSPZKJzBcc7WV9L4nmia3KDZDrlaZX3 IngAFlpNaL8gv33Vx5OArb1AFeDvkt8fke0uP/bM6yFCppYQ5nWT/g8/PD0SfgM4FeCKB9 jrIWs/65U6pGyC5YcsZ2LX5c9JcKuIQ= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-210--JzF20M8MySZowuuoKzrzA-1; Tue, 03 Nov 2020 09:34:35 -0500 X-MC-Unique: -JzF20M8MySZowuuoKzrzA-1 Received: by mail-wm1-f70.google.com with SMTP id l16so2703643wmh.1 for ; Tue, 03 Nov 2020 06:34:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=4t5NY5zyTFxf5JdPvPR+dRhfn/ny8MSoW1vs+UM3VkI=; b=XDJFyD5vNFkAw09MyD2MWyOO6knihCEsqf30Tnmei7t5IbtZiWSdIjYTQ5SrLSmsaR 8z3X5YM6DWUUEFrucngHhKGg31jGzYXvtpSCUhVvtOsttosVLjHRzp41AbrGSH4RO3tV 12Y5A/bX816imKinEWab6qM0hX8OTIrIZg4pYcPB/WNXPIH8EbLpz42URSnFGRcYBWfC adaOuJqjHpWm9+Fe2lwctEeujM9U5HAkcMyFiUQ7ch4bFbbiXR9OyvNMzEKzSs7mefAo wSHmS8Hfc24dB6oJoeBxjQjbYGfS1UUixb1yKlFRL17vIbyV+66DLcW0ZjzXyDn3YGyr zfdg== X-Gm-Message-State: AOAM5333bb5VVvkJePjE/1pAmq4Ok1PtBF56A/YzVywEml6bTVkHeHlB NwRBHuM3JCuREoeQb63GutqqFFBb44KEthuHN41HCFHSIBUUw+0k4+xVXcQ7T4dOmAyMpudV+W9 3TlZsIXRE2aM5/Ls= X-Received: by 2002:adf:ea0e:: with SMTP id q14mr26129648wrm.373.1604414072888; Tue, 03 Nov 2020 06:34:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJwireeXor2w1ab/4FxGfEn44C89A1cVQHfyhSkn3leFSmAyEHLXzqE6R+joZWF3lxMKZfoVRA== X-Received: by 2002:adf:ea0e:: with SMTP id q14mr26129631wrm.373.1604414072695; Tue, 03 Nov 2020 06:34:32 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id j71sm3391633wmj.10.2020.11.03.06.34.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:32 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:30 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 11/38] hw/virtio/vhost-backend: Fix Coverity CID 1432871 Message-ID: <20201103142306.71782-12-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Philippe =?utf-8?q?Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , Stefano Garzarella Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Philippe Mathieu-Daudé Fix uninitialized value issues reported by Coverity: Field 'msg.reserved' is uninitialized when calling write(). While the 'struct vhost_msg' does not have a 'reserved' field, we still initialize it to have the two parts of the function consistent. Reported-by: Coverity (CID 1432864: UNINIT) Fixes: c471ad0e9bd ("vhost_net: device IOTLB support") Reviewed-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20201103063541.2463363-1-philmd@redhat.com> Reviewed-by: Stefano Garzarella Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost-backend.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c index 88c8ecc9e0..222bbcc62d 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -257,7 +257,7 @@ static int vhost_kernel_send_device_iotlb_msg(struct vhost_dev *dev, struct vhost_iotlb_msg *imsg) { if (dev->backend_cap & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2)) { - struct vhost_msg_v2 msg; + struct vhost_msg_v2 msg = {}; msg.type = VHOST_IOTLB_MSG_V2; msg.iotlb = *imsg; @@ -267,7 +267,7 @@ static int vhost_kernel_send_device_iotlb_msg(struct vhost_dev *dev, return -EFAULT; } } else { - struct vhost_msg msg; + struct vhost_msg msg = {}; msg.type = VHOST_IOTLB_MSG; msg.iotlb = *imsg; From patchwork Tue Nov 3 14:34:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877833 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 8FAF96A2 for ; Tue, 3 Nov 2020 14:52:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 21A322076E for ; Tue, 3 Nov 2020 14:52:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KyG55BLj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 21A322076E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:40098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxfP-0001jF-3s for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:52:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33170) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxOd-0004TV-0d for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:30875) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxOa-0006Sl-QS for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414087; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QTkwT/HJ1lj3VKT9unaRe9zAEsq3t6jIEnXFjz8fDHg=; b=KyG55BLjo1TMDH5VtfFwR2c6vIe9nofLO1VcgBlV9DfdvL9zGwvWQIlksFmeSit8Z/u8Ir 5/pLOTTpJoh4GjqcRZcfs7O/dMmyFe7O7Eyo3jYLvuTTG5ZHRK2Lmj/oGsr/6ZaF9QzYeg J/IdYyjC2m1aiOp+KPCIpxh4dZY6qzc= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-98-qtVob46sPLmeEzZ8RICBpw-1; Tue, 03 Nov 2020 09:34:37 -0500 X-MC-Unique: qtVob46sPLmeEzZ8RICBpw-1 Received: by mail-wm1-f72.google.com with SMTP id c10so3821438wmh.6 for ; Tue, 03 Nov 2020 06:34:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=QTkwT/HJ1lj3VKT9unaRe9zAEsq3t6jIEnXFjz8fDHg=; b=loRJN05eF6u8TkOH4in0ZOmdFrDzGkoLpXwEink+k3TzoSpp7SK0eiP7FDFR+b0BiA qyz8HSz7vxZ1PGDd9CJJTuAeR0pHrfxNj00AdFyymbpj1NpNas/J4HiD409Hxp+1YTnb 0Upc+DZ8AYW57mNb60+ERRvWA7E/hvfCUsg2c6m8/U8Vdje6nBYSgDMqVoqQUBKt8g45 KgoChDQP9nvI5DRhBJmTTLTIgIZjxYmB0CEb3deMkh1ifmN8SFLZ5bq+mj4iU+kA0MNF e/wLwVHwUq+7jbY73Mx+WeUqRC19vv9ecXXuT+zub2kGJE/uia6mKbPMWszUky5p+nVA Z4Vw== X-Gm-Message-State: AOAM533mwzFGa+hiWcg6nQKVmth2R9cTsqQnF51xmB3pFStFH5y0O2Zs 5R5VAQCipCpGBaA0018ivmu9V8EEO49YR0C3tWw5dEDL003KxZlRwZypRCn2GgCqTGWHMGtluLI NxY7dgnp4m3TAaK4= X-Received: by 2002:a5d:4581:: with SMTP id p1mr26440926wrq.353.1604414075528; Tue, 03 Nov 2020 06:34:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJw9L697Du0dzc7wR99MIjOGGMPL/JcEtGEA5Jy7QuBJZt71LCvFWOcFPrTWK4x6fpc6FhZK5Q== X-Received: by 2002:a5d:4581:: with SMTP id p1mr26440911wrq.353.1604414075382; Tue, 03 Nov 2020 06:34:35 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id u3sm24771383wro.33.2020.11.03.06.34.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:34 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:33 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 12/38] hw/smbios: Fix leaked fd in save_opt_one() error path Message-ID: <20201103142306.71782-13-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Igor Mammedov , Philippe =?utf-8?q?Mathieu-Daud=C3=A9?= , Laszlo Ersek , Stefano Garzarella Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Philippe Mathieu-Daudé Fix the following Coverity issue (RESOURCE_LEAK): CID 1432879: Resource leak Handle variable fd going out of scope leaks the handle. Replace a close() call by qemu_close() since the handle is opened with qemu_open(). Fixes: bb99f4772f5 ("hw/smbios: support loading OEM strings values from a file") Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20201030152742.1553968-1-philmd@redhat.com> Reviewed-by: Stefano Garzarella Reviewed-by: Laszlo Ersek Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/smbios/smbios.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c index 8b30906e50..6a3d39793b 100644 --- a/hw/smbios/smbios.c +++ b/hw/smbios/smbios.c @@ -988,16 +988,18 @@ static int save_opt_one(void *opaque, if (ret < 0) { error_setg(errp, "Unable to read from %s: %s", value, strerror(errno)); + qemu_close(fd); return -1; } if (memchr(buf, '\0', ret)) { error_setg(errp, "NUL in OEM strings value in %s", value); + qemu_close(fd); return -1; } g_byte_array_append(data, (guint8 *)buf, ret); } - close(fd); + qemu_close(fd); *opt->dest = g_renew(char *, *opt->dest, (*opt->ndest) + 1); (*opt->dest)[*opt->ndest] = (char *)g_byte_array_free(data, FALSE); From patchwork Tue Nov 3 14:34:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877817 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 3B2FD92A for ; Tue, 3 Nov 2020 14:47:17 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A91002242E for ; Tue, 3 Nov 2020 14:47:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OdgghKpJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A91002242E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:51448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxad-00037M-K4 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:47:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxOW-0004Qd-K3 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:37871) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxOU-0006Qc-CH for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414081; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=yb0+hTu/cI4h7Se3wHsf9S5j6pZCfXhlBpQERrIdWig=; b=OdgghKpJ7zVu2t5hjK2KlS4oFdrLKNu6glSSTVxR/R3DvFuNrSlF8AWyHFGPtqPlO0r/pm kEgcPMxXAsmQdtVYCH2P/UWMh3H2x5mLPMXG2tDr8O6Cl98LdkRUbHqvLjg6Vbq0/z8ZWr ieyGhCMGOFquf6shhqJ5ceT4YBgG40Y= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-1-930sj2E2NmyyAftRlFy71Q-1; Tue, 03 Nov 2020 09:34:39 -0500 X-MC-Unique: 930sj2E2NmyyAftRlFy71Q-1 Received: by mail-wm1-f71.google.com with SMTP id 13so4685101wmf.0 for ; Tue, 03 Nov 2020 06:34:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=yb0+hTu/cI4h7Se3wHsf9S5j6pZCfXhlBpQERrIdWig=; b=habhOs6x5K3/nsGiHoyzZv+4oFQfeW0PiU6Zl1v6C4Fm936x6LXreffSHP1owKXNhi Fp5vMu7FvA7G8s2HhxD2wKJt9EJcq++9v+nH3PjBpvDcpodi3yRfqvKEWiGb4ciM58ss hb+pP9BVjOqAuUWA5SE6KyS3OwMsGZ5SssOPE1mLgcGP1HL8ef9C6BX3GHabEPk5JQrm QmLD7GN8VM9CxI38xB14OGa7Ks4h8eum1I6ZFuVb12cx719FlGLB4nLOe/w6tNNrg3Wc 2tVpl+9ctOhjIomrLuGWxDBsSt4EW1qNKd8Np377jTzpbr0QsNgzfybRbhN3D3xb+ehI +cLg== X-Gm-Message-State: AOAM533ZIzbYqhaMCszc2BsszqhAKzw6rQ56oSrjri7HF5lWFancaTIC TPHFm1uwSbQnVBDhL87kLubUxDDp6h/P2DIr13cqwXcMAO1+OI6hdVcPSmn5SfxBteuTa2uDCon rCgUAALmUCjht/ng= X-Received: by 2002:a1c:cc06:: with SMTP id h6mr37214wmb.29.1604414077998; Tue, 03 Nov 2020 06:34:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJwDKkZEbgL2lKYNQIALJ38BQL2QQcAGhZ9O54UBH57kkvv5ICqYDtjobZv/mMW/Q1/ScYROSA== X-Received: by 2002:a1c:cc06:: with SMTP id h6mr37202wmb.29.1604414077866; Tue, 03 Nov 2020 06:34:37 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id e3sm26582657wrn.32.2020.11.03.06.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:37 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:35 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 13/38] virtio-iommu: Fix virtio_iommu_mr() Message-ID: <20201103142306.71782-14-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Peter Xu , QEMU Stable , Eric Auger , Jean-Philippe Brucker Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Jean-Philippe Brucker Due to an invalid mask, virtio_iommu_mr() may return the wrong memory region. It hasn't been too problematic so far because the function was only used to test existence of an endpoint, but that is about to change. Fixes: cfb42188b24d ("virtio-iommu: Implement attach/detach command") Cc: QEMU Stable Acked-by: Eric Auger Reviewed-by: Peter Xu Signed-off-by: Jean-Philippe Brucker Message-Id: <20201030180510.747225-2-jean-philippe@linaro.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 21ec63b108..4c8f3909b7 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -101,7 +101,7 @@ static IOMMUMemoryRegion *virtio_iommu_mr(VirtIOIOMMU *s, uint32_t sid) bus_n = PCI_BUS_NUM(sid); iommu_pci_bus = iommu_find_iommu_pcibus(s, bus_n); if (iommu_pci_bus) { - devfn = sid & PCI_DEVFN_MAX; + devfn = sid & (PCI_DEVFN_MAX - 1); dev = iommu_pci_bus->pbdev[devfn]; if (dev) { return &dev->iommu_mr; From patchwork Tue Nov 3 14:34:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877825 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 CC4AD92A for ; Tue, 3 Nov 2020 14:49:31 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8377D22447 for ; Tue, 3 Nov 2020 14:49:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Kz3ghn3+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8377D22447 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:59882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxco-0006aE-IN for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:49:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33130) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxOY-0004RS-J9 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52662) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxOW-0006Ra-MW for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414083; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=tvJ0s3bSV9g9bsoYugn7fOSbhCEdSfwOqB79D2kkBqw=; b=Kz3ghn3+Jc6mvM+/CRRbHDjfOFK/NS4K3JWPZpYeiQx/MN8l1DteYlql3sJxOAP7mma8gR A+7zB0olYfoYoGPG5PoEBPkGCT7Rw/8tkEG0EDLln7AKyXFZCxy7Xq9vcaLIdg3YfOF9sh 3YBm/s1PWnQ95cvroc/A7MClm8RynZI= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-40-le-CMJBiO0OAGCueklnhXw-1; Tue, 03 Nov 2020 09:34:41 -0500 X-MC-Unique: le-CMJBiO0OAGCueklnhXw-1 Received: by mail-wr1-f72.google.com with SMTP id h11so4934621wrq.20 for ; Tue, 03 Nov 2020 06:34:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=tvJ0s3bSV9g9bsoYugn7fOSbhCEdSfwOqB79D2kkBqw=; b=VgDUTojsyJqM0B4L2f7D2CON+GkDzvRBoWnpQlVoVZMpeCc5Dj5cOBn5jcjDbY3qC2 kxnobB68vEgfJfTweG7nOUPj7c+71R2Wf3LD3lnm+Vzrb66OHbHDln+4TG/KTNYVRv1Q lOoIMIqRHg2OaZzNAU5WouWqLbJlJem44BbD6i4mvZRXPW2mWrlyipB1QHM0BjAxFPio TRqDDFhUr1KYrs0BhIpIiyKBeZBJxnSg+UfM5NWgYADO++nTQ7cuvq1vyfY9aLTJ+rHG F7U6cYuT+OyvknTPr+JFc5dbTkttTUL/tTAFqn3rc3rvd8tgslZlgJrCjdga23jmEzRG sIAQ== X-Gm-Message-State: AOAM533et+F3pYbqtuLkBpLMEr9jWzJqWCZQ/4JT9rClkiONatJe1bfh NHbohp3R2o45CKvb8mQJnaN7K+jEP2Vz0vwclSk8AWJW0C9ILZwdkAkgUzMABSk/Q5cQvowX+6D R+hdsaBIpJa74zvQ= X-Received: by 2002:adf:9507:: with SMTP id 7mr26641035wrs.365.1604414080318; Tue, 03 Nov 2020 06:34:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJyMqjGRNdrz5dKP3iX6OZ9xBVE1j5SUJJK7cq6avxEZoZyMx5TChWRWDqsLnu3HwCSML1gsqA== X-Received: by 2002:adf:9507:: with SMTP id 7mr26641016wrs.365.1604414080170; Tue, 03 Nov 2020 06:34:40 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id v12sm27398133wro.72.2020.11.03.06.34.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:39 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:38 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 14/38] virtio-iommu: Store memory region in endpoint struct Message-ID: <20201103142306.71782-15-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Eric Auger , Jean-Philippe Brucker Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Jean-Philippe Brucker Store the memory region associated to each endpoint into the endpoint structure, to allow efficient memory notification on map/unmap. Acked-by: Eric Auger Signed-off-by: Jean-Philippe Brucker Message-Id: <20201030180510.747225-3-jean-philippe@linaro.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-iommu.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 4c8f3909b7..a5c2d69aad 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -49,6 +49,7 @@ typedef struct VirtIOIOMMUDomain { typedef struct VirtIOIOMMUEndpoint { uint32_t id; VirtIOIOMMUDomain *domain; + IOMMUMemoryRegion *iommu_mr; QLIST_ENTRY(VirtIOIOMMUEndpoint) next; } VirtIOIOMMUEndpoint; @@ -137,16 +138,19 @@ static VirtIOIOMMUEndpoint *virtio_iommu_get_endpoint(VirtIOIOMMU *s, uint32_t ep_id) { VirtIOIOMMUEndpoint *ep; + IOMMUMemoryRegion *mr; ep = g_tree_lookup(s->endpoints, GUINT_TO_POINTER(ep_id)); if (ep) { return ep; } - if (!virtio_iommu_mr(s, ep_id)) { + mr = virtio_iommu_mr(s, ep_id); + if (!mr) { return NULL; } ep = g_malloc0(sizeof(*ep)); ep->id = ep_id; + ep->iommu_mr = mr; trace_virtio_iommu_get_endpoint(ep_id); g_tree_insert(s->endpoints, GUINT_TO_POINTER(ep_id), ep); return ep; @@ -910,9 +914,14 @@ static gboolean reconstruct_endpoints(gpointer key, gpointer value, VirtIOIOMMU *s = (VirtIOIOMMU *)data; VirtIOIOMMUDomain *d = (VirtIOIOMMUDomain *)value; VirtIOIOMMUEndpoint *iter; + IOMMUMemoryRegion *mr; QLIST_FOREACH(iter, &d->endpoint_list, next) { + mr = virtio_iommu_mr(s, iter->id); + assert(mr); + iter->domain = d; + iter->iommu_mr = mr; g_tree_insert(s->endpoints, GUINT_TO_POINTER(iter->id), iter); } return false; /* continue the domain traversal */ From patchwork Tue Nov 3 14:34:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877819 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 94C0F92A for ; Tue, 3 Nov 2020 14:47:19 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 36F572242F for ; Tue, 3 Nov 2020 14:47:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BEa0oNxD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 36F572242F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:51672 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxag-0003DF-1X for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:47:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33168) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxOc-0004Sp-Ex for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:59244) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxOa-0006Sj-GC for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414087; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=2pTrzfIlEtuFgKli+YZx2cSmkYnPe9QRNfZXCU2zweM=; b=BEa0oNxDy6k8PCxfgx0Gdwef6wlTPJ9lyCnadc0SSpBtuGqW/kE0hS+TaxbOjZBx/ZGI9d PpKFF1WyerqJb+C2umxzjg+SdIUuws6l+dajMGVEqhBNZlRJrQXIkNDrPSiKpxFYc/SRM8 vO7rF9ye3mWvovMZyheiLaC+97pIgIA= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-476-kIHWBnKVOleuADpvZ2kHIA-1; Tue, 03 Nov 2020 09:34:44 -0500 X-MC-Unique: kIHWBnKVOleuADpvZ2kHIA-1 Received: by mail-wr1-f70.google.com with SMTP id t14so7948888wrs.2 for ; Tue, 03 Nov 2020 06:34:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=2pTrzfIlEtuFgKli+YZx2cSmkYnPe9QRNfZXCU2zweM=; b=Vbs69UYseOFYCQM5DMZnHoWxu5RR6L3/8pkaXGxKkTsh+P9ovpvIRJeoPL6380EJE4 UxKmx+khai0Ufr9HQZxbbMBv8OPtCzvbU0h/iO/yCh7dCldEmX4Bf7Nx9epRmc6i66i9 nXrxnhmbmaDjWOYxY16+Oek5laDtY9gEaHtD/NZ65nvKSFH1clny/2DTOb5tqGYKHWiZ mkoFpkvqBOT/yhE9JLNs+VFunzTeiqsJX0WvoHeYtqiWyyzSlL2HbfKW6Xq57y6YMcD6 NtvnREw/ncssU7Kd2aESeANgXeabLym4OO8f3z9IWfh7qs1++Uaq1eQH+IfI/JgOdWTk 47PA== X-Gm-Message-State: AOAM530Iuuh2Km2PberKNX22zws0bc+pScN8Qj9N40D7VrVgBVqwvlhu 9VPsS46lm5g/Iq7hVvf3z3gBy6XYuJQSLwPlmEorUu65hxuo28YgUZ4HxcpXrdy0vxIVDJEwQ4q NvqJNWRSWtVXtUKY= X-Received: by 2002:a5d:5106:: with SMTP id s6mr25823728wrt.51.1604414082839; Tue, 03 Nov 2020 06:34:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJxEURiwTIaVPyJm6L/A8QQpo9yfQbld4Pda93fnz4ZnCdyHPXxk4NEGjhkQoUKSEsLRLZHiEg== X-Received: by 2002:a5d:5106:: with SMTP id s6mr25823709wrt.51.1604414082595; Tue, 03 Nov 2020 06:34:42 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id v19sm3011422wmj.31.2020.11.03.06.34.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:41 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:40 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 15/38] virtio-iommu: Add memory notifiers for map/unmap Message-ID: <20201103142306.71782-16-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Bharat Bhushan , Jean-Philippe Brucker , Eric Auger Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bharat Bhushan Extend VIRTIO_IOMMU_T_MAP/UNMAP request to notify memory listeners. It will call VFIO notifier to map/unmap regions in the physical IOMMU. Signed-off-by: Bharat Bhushan Signed-off-by: Eric Auger Signed-off-by: Jean-Philippe Brucker Message-Id: <20201030180510.747225-4-jean-philippe@linaro.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-iommu.c | 56 ++++++++++++++++++++++++++++++++++++++++ hw/virtio/trace-events | 2 ++ 2 files changed, 58 insertions(+) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index a5c2d69aad..7dd15c5eac 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -125,6 +125,51 @@ static gint interval_cmp(gconstpointer a, gconstpointer b, gpointer user_data) } } +static void virtio_iommu_notify_map(IOMMUMemoryRegion *mr, hwaddr virt_start, + hwaddr virt_end, hwaddr paddr, + uint32_t flags) +{ + IOMMUTLBEntry entry; + IOMMUAccessFlags perm = IOMMU_ACCESS_FLAG(flags & VIRTIO_IOMMU_MAP_F_READ, + flags & VIRTIO_IOMMU_MAP_F_WRITE); + + if (!(mr->iommu_notify_flags & IOMMU_NOTIFIER_MAP) || + (flags & VIRTIO_IOMMU_MAP_F_MMIO) || !perm) { + return; + } + + trace_virtio_iommu_notify_map(mr->parent_obj.name, virt_start, virt_end, + paddr, perm); + + entry.target_as = &address_space_memory; + entry.addr_mask = virt_end - virt_start; + entry.iova = virt_start; + entry.perm = perm; + entry.translated_addr = paddr; + + memory_region_notify_iommu(mr, 0, entry); +} + +static void virtio_iommu_notify_unmap(IOMMUMemoryRegion *mr, hwaddr virt_start, + hwaddr virt_end) +{ + IOMMUTLBEntry entry; + + if (!(mr->iommu_notify_flags & IOMMU_NOTIFIER_UNMAP)) { + return; + } + + trace_virtio_iommu_notify_unmap(mr->parent_obj.name, virt_start, virt_end); + + entry.target_as = &address_space_memory; + entry.addr_mask = virt_end - virt_start; + entry.iova = virt_start; + entry.perm = IOMMU_NONE; + entry.translated_addr = 0; + + memory_region_notify_iommu(mr, 0, entry); +} + static void virtio_iommu_detach_endpoint_from_domain(VirtIOIOMMUEndpoint *ep) { if (!ep->domain) { @@ -315,6 +360,7 @@ static int virtio_iommu_map(VirtIOIOMMU *s, VirtIOIOMMUDomain *domain; VirtIOIOMMUInterval *interval; VirtIOIOMMUMapping *mapping; + VirtIOIOMMUEndpoint *ep; if (flags & ~VIRTIO_IOMMU_MAP_F_MASK) { return VIRTIO_IOMMU_S_INVAL; @@ -344,6 +390,11 @@ static int virtio_iommu_map(VirtIOIOMMU *s, g_tree_insert(domain->mappings, interval, mapping); + QLIST_FOREACH(ep, &domain->endpoint_list, next) { + virtio_iommu_notify_map(ep->iommu_mr, virt_start, virt_end, phys_start, + flags); + } + return VIRTIO_IOMMU_S_OK; } @@ -356,6 +407,7 @@ static int virtio_iommu_unmap(VirtIOIOMMU *s, VirtIOIOMMUMapping *iter_val; VirtIOIOMMUInterval interval, *iter_key; VirtIOIOMMUDomain *domain; + VirtIOIOMMUEndpoint *ep; int ret = VIRTIO_IOMMU_S_OK; trace_virtio_iommu_unmap(domain_id, virt_start, virt_end); @@ -373,6 +425,10 @@ static int virtio_iommu_unmap(VirtIOIOMMU *s, uint64_t current_high = iter_key->high; if (interval.low <= current_low && interval.high >= current_high) { + QLIST_FOREACH(ep, &domain->endpoint_list, next) { + virtio_iommu_notify_unmap(ep->iommu_mr, current_low, + current_high); + } g_tree_remove(domain->mappings, iter_key); trace_virtio_iommu_unmap_done(domain_id, current_low, current_high); } else { diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index cf1e59de30..b87a397406 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -106,6 +106,8 @@ virtio_iommu_put_domain(uint32_t domain_id) "Free domain=%d" virtio_iommu_translate_out(uint64_t virt_addr, uint64_t phys_addr, uint32_t sid) "0x%"PRIx64" -> 0x%"PRIx64 " for sid=%d" virtio_iommu_report_fault(uint8_t reason, uint32_t flags, uint32_t endpoint, uint64_t addr) "FAULT reason=%d flags=%d endpoint=%d address =0x%"PRIx64 virtio_iommu_fill_resv_property(uint32_t devid, uint8_t subtype, uint64_t start, uint64_t end) "dev= %d, type=%d start=0x%"PRIx64" end=0x%"PRIx64 +virtio_iommu_notify_map(const char *name, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start, uint32_t flags) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64" phys_start=0x%"PRIx64" flags=%d" +virtio_iommu_notify_unmap(const char *name, uint64_t virt_start, uint64_t virt_end) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64 # virtio-mem.c virtio_mem_send_response(uint16_t type) "type=%" PRIu16 From patchwork Tue Nov 3 14:34:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877877 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 C29A292A for ; Tue, 3 Nov 2020 14:58:19 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8958C20757 for ; Tue, 3 Nov 2020 14:58:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Frw3ouKu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8958C20757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxlK-0002SS-Kv for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:58:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34378) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxRr-00006D-1L for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:38:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:44533) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxRo-0007fw-Vv for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:38:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=CO5kV6TOgl7VkllXO+Cj7QHVQ3FQj45OIYdaYC1hBZU=; b=Frw3ouKuBlR5IGlKInQb8KoGK1l+6PvhzhztT3mc068BBH/ovMZc2jUsfIXva2dgBwlU/a z5fzJiJiS8jop9tRyF8eEkDjGrwAaKz39g2HtIrJoxYERGKy+I48t1jqYtDSZ1BJx6+OYO 1MlQMEYTbTtcxR3O205WjKOdNlcxWZc= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-107-8L66t7TsMPqQDZ3wA5TVaw-1; Tue, 03 Nov 2020 09:34:47 -0500 X-MC-Unique: 8L66t7TsMPqQDZ3wA5TVaw-1 Received: by mail-wm1-f72.google.com with SMTP id z7so4670466wme.8 for ; Tue, 03 Nov 2020 06:34:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=CO5kV6TOgl7VkllXO+Cj7QHVQ3FQj45OIYdaYC1hBZU=; b=S4oALmZ9jlwfJkGejh8lypY6Vp4dLu8ZnGdDjQ4CTjWyD/wEAue0F5MZ/iEJyLBkDu lx87rCWpdVTFvuG5k215zmkvTZBSyeOeK+GQE7IUhOviCcn1sq0cmxDjfNbw6HRvkNhT XyWphVrAdKZa0Rpm6AYuuo+0JPK07g0qOiItcL1KilLUZwAgelUpZkJ7Jaa3VYrVMNO/ JUHoE5lWu58Wi99SsvnhhpE7j9jvoc4Nf+xxkUsr1dU/83efkOgglNaF9N3c+LzQ1z1m ADGCo19Z/hjBLLytDYnfXFRioeFfnHOWNGTonISvIXAP1l3fUUd2vdLRZ32ZPkWSjx5l kBHA== X-Gm-Message-State: AOAM531M1KdUIz+b+/gKmjfK//QGb58XswmoLyr3LmjwhvqMlNlNnIin M6wjf5pGwqqfhVVDUs4ef42EU2jw777ySsB4oUwTHo/5W+v90FaTrdVRJX1aE7Zd86Z/H/64ypW m7hcoVziUTrPBso8= X-Received: by 2002:adf:f20e:: with SMTP id p14mr25733376wro.376.1604414085441; Tue, 03 Nov 2020 06:34:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJycKFIn+1p6nKCuBF+jY+mIK8n0wzysbh//uAD9L6WzpSfxSpZC4bfThjDva8j9aRcovolh4w== X-Received: by 2002:adf:f20e:: with SMTP id p14mr25733358wro.376.1604414085239; Tue, 03 Nov 2020 06:34:45 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id a15sm718229wrn.75.2020.11.03.06.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:44 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:42 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 16/38] virtio-iommu: Call memory notifiers in attach/detach Message-ID: <20201103142306.71782-17-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Bharat Bhushan , Eric Auger , Jean-Philippe Brucker Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bharat Bhushan Call the memory notifiers when attaching an endpoint to a domain, to replay existing mappings, and when detaching the endpoint, to remove all mappings. Signed-off-by: Bharat Bhushan Signed-off-by: Jean-Philippe Brucker Message-Id: <20201030180510.747225-5-jean-philippe@linaro.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-iommu.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 7dd15c5eac..7b64892351 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -170,11 +170,39 @@ static void virtio_iommu_notify_unmap(IOMMUMemoryRegion *mr, hwaddr virt_start, memory_region_notify_iommu(mr, 0, entry); } +static gboolean virtio_iommu_notify_unmap_cb(gpointer key, gpointer value, + gpointer data) +{ + VirtIOIOMMUInterval *interval = (VirtIOIOMMUInterval *) key; + IOMMUMemoryRegion *mr = (IOMMUMemoryRegion *) data; + + virtio_iommu_notify_unmap(mr, interval->low, interval->high); + + return false; +} + +static gboolean virtio_iommu_notify_map_cb(gpointer key, gpointer value, + gpointer data) +{ + VirtIOIOMMUMapping *mapping = (VirtIOIOMMUMapping *) value; + VirtIOIOMMUInterval *interval = (VirtIOIOMMUInterval *) key; + IOMMUMemoryRegion *mr = (IOMMUMemoryRegion *) data; + + virtio_iommu_notify_map(mr, interval->low, interval->high, + mapping->phys_addr, mapping->flags); + + return false; +} + static void virtio_iommu_detach_endpoint_from_domain(VirtIOIOMMUEndpoint *ep) { + VirtIOIOMMUDomain *domain = ep->domain; + if (!ep->domain) { return; } + g_tree_foreach(domain->mappings, virtio_iommu_notify_unmap_cb, + ep->iommu_mr); QLIST_REMOVE(ep, next); ep->domain = NULL; } @@ -317,6 +345,10 @@ static int virtio_iommu_attach(VirtIOIOMMU *s, ep->domain = domain; + /* Replay domain mappings on the associated memory region */ + g_tree_foreach(domain->mappings, virtio_iommu_notify_map_cb, + ep->iommu_mr); + return VIRTIO_IOMMU_S_OK; } From patchwork Tue Nov 3 14:34:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877807 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 57F1F921 for ; Tue, 3 Nov 2020 14:42:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1741D223AC for ; Tue, 3 Nov 2020 14:42:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="a1kbaqT7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1741D223AC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:37672 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxVt-0005fJ-5X for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:42:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxOi-0004Xu-3e for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:56 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:37334) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxOg-0006Tz-7h for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414091; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Vj2K5KfIjYgXaS/HA+9u99+5hxZOJUDzQMD8f8h61Sg=; b=a1kbaqT78C8aHRwqf1cDB3A57z+0Tiv2lpEuXs1vY30mlXBf2EOVoG4e2hOtPK4Rto6hZl iiroUOkRJE23bz33JAm+b64/B33s+711YZCt2HSwuhsuAJGUOtVUEUY9/oBZhciCiJjOIJ osK/nNsZfSwHUNqx5kO+40N1g+uE2OM= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-120-0u1rXwTQMpOWoSs7KqStIg-1; Tue, 03 Nov 2020 09:34:49 -0500 X-MC-Unique: 0u1rXwTQMpOWoSs7KqStIg-1 Received: by mail-wr1-f71.google.com with SMTP id w3so5768511wrt.11 for ; Tue, 03 Nov 2020 06:34:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Vj2K5KfIjYgXaS/HA+9u99+5hxZOJUDzQMD8f8h61Sg=; b=TsYORLyghmDaCMcYB/IUEtOZxpk38mb2fsUCSw3UcbL2M9vkAD/lueC+DDweF2gvTr nQSL7dci5WBybD3NGrM1VOyg6zdB8EoJyQb3sKS+hWHAZhfxzUBCAQBF5YbZWUPRU4ea L6h4ZxNbrGWtSQy6fIICIDd/aGLpPzwM0kAYICa8SPkTUkLwcqFArKDcU1n7v96sL0p9 2LrSGBCetLLo8MIB7TS5ZY2mFleBKytbqrDJww0ywHCYEO2unUTqHv3TPAxfASYPf9IK o3V1CLjaUFmp7UIt3gLl4/eQ9VHsijboh3nfVoFaKPUKyuSIKgFtWolZdpQiavxNPCw3 5Kjw== X-Gm-Message-State: AOAM5306wKsaIadmbV142sHGtCNwvC+QoaHrhem/HJVcijH+FuRyn6FP oTIBJOdbQcswjAYKxVyec2B7vUhu9ZpLqW8Dd4USDOwZvBfr0xWG4s1lsw6WCEr1OsDVLXoYDZr V6VCTvYRT+pl0dSc= X-Received: by 2002:a1c:9a0e:: with SMTP id c14mr40648wme.35.1604414087945; Tue, 03 Nov 2020 06:34:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJyhzHA13Ma23FcbGBtarWK9GJrHrxMVBl9rPsWvEdNrSq5TiHTNDqscNcR1KyyJAYL9E1KPLg== X-Received: by 2002:a1c:9a0e:: with SMTP id c14mr40628wme.35.1604414087763; Tue, 03 Nov 2020 06:34:47 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id b4sm18307094wro.57.2020.11.03.06.34.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:47 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:45 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 17/38] virtio-iommu: Add replay() memory region callback Message-ID: <20201103142306.71782-18-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Bharat Bhushan , Eric Auger , Jean-Philippe Brucker Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bharat Bhushan Implement the replay callback to setup all mappings for a new memory region. Signed-off-by: Bharat Bhushan Signed-off-by: Jean-Philippe Brucker Message-Id: <20201030180510.747225-6-jean-philippe@linaro.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-iommu.c | 40 ++++++++++++++++++++++++++++++++++++++++ hw/virtio/trace-events | 1 + 2 files changed, 41 insertions(+) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 7b64892351..985257c88f 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -847,6 +847,45 @@ static gint int_cmp(gconstpointer a, gconstpointer b, gpointer user_data) return (ua > ub) - (ua < ub); } +static gboolean virtio_iommu_remap(gpointer key, gpointer value, gpointer data) +{ + VirtIOIOMMUMapping *mapping = (VirtIOIOMMUMapping *) value; + VirtIOIOMMUInterval *interval = (VirtIOIOMMUInterval *) key; + IOMMUMemoryRegion *mr = (IOMMUMemoryRegion *) data; + + trace_virtio_iommu_remap(mr->parent_obj.name, interval->low, interval->high, + mapping->phys_addr); + virtio_iommu_notify_map(mr, interval->low, interval->high, + mapping->phys_addr, mapping->flags); + return false; +} + +static void virtio_iommu_replay(IOMMUMemoryRegion *mr, IOMMUNotifier *n) +{ + IOMMUDevice *sdev = container_of(mr, IOMMUDevice, iommu_mr); + VirtIOIOMMU *s = sdev->viommu; + uint32_t sid; + VirtIOIOMMUEndpoint *ep; + + sid = virtio_iommu_get_bdf(sdev); + + qemu_mutex_lock(&s->mutex); + + if (!s->endpoints) { + goto unlock; + } + + ep = g_tree_lookup(s->endpoints, GUINT_TO_POINTER(sid)); + if (!ep || !ep->domain) { + goto unlock; + } + + g_tree_foreach(ep->domain->mappings, virtio_iommu_remap, mr); + +unlock: + qemu_mutex_unlock(&s->mutex); +} + static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); @@ -1076,6 +1115,7 @@ static void virtio_iommu_memory_region_class_init(ObjectClass *klass, IOMMUMemoryRegionClass *imrc = IOMMU_MEMORY_REGION_CLASS(klass); imrc->translate = virtio_iommu_translate; + imrc->replay = virtio_iommu_replay; } static const TypeInfo virtio_iommu_info = { diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index b87a397406..ea3c3b25ad 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -108,6 +108,7 @@ virtio_iommu_report_fault(uint8_t reason, uint32_t flags, uint32_t endpoint, uin virtio_iommu_fill_resv_property(uint32_t devid, uint8_t subtype, uint64_t start, uint64_t end) "dev= %d, type=%d start=0x%"PRIx64" end=0x%"PRIx64 virtio_iommu_notify_map(const char *name, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start, uint32_t flags) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64" phys_start=0x%"PRIx64" flags=%d" virtio_iommu_notify_unmap(const char *name, uint64_t virt_start, uint64_t virt_end) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64 +virtio_iommu_remap(const char *name, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64" phys_start=0x%"PRIx64 # virtio-mem.c virtio_mem_send_response(uint16_t type) "type=%" PRIu16 From patchwork Tue Nov 3 14:34:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877839 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 091DA92A for ; Tue, 3 Nov 2020 14:54:24 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B5A77223BF for ; Tue, 3 Nov 2020 14:54:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WvIg5Bz7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B5A77223BF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:48452 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxhW-0005Ee-Mz for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:54:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33206) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxOj-0004Yh-8b for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51377) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxOh-0006Us-II for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414094; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FfMG5NPSSgbiHzXp+0EZ66dpqrizcgkZqiSRInNVyXY=; b=WvIg5Bz7kWyACPE2Pc5k3ykhKIgK1D6aXpAuzqb604ucSlSeszLE+VJ4SSn7PmPeXUMc81 ziPnBCRY3uAVgvqugf9Zv+ht7Vh1GqOvCDXrkpX2/oYBeAKT2s1+RWxuZJzVqswh5Dqvvl DLlvkxnp9MfA6BTmv+6Z5h7Zid+o77Q= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-557-rug7h1QyO064ww2KBJ8oXQ-1; Tue, 03 Nov 2020 09:34:53 -0500 X-MC-Unique: rug7h1QyO064ww2KBJ8oXQ-1 Received: by mail-wm1-f70.google.com with SMTP id u9so1599979wmb.2 for ; Tue, 03 Nov 2020 06:34:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=FfMG5NPSSgbiHzXp+0EZ66dpqrizcgkZqiSRInNVyXY=; b=NT92TNFmgxL8SVOR1K29B7byQLqReJGRmo4g7N3XuAbjM+JqF2wYhtmcGhgT4YDOX/ n1wRwJFw7ofiyQeiI4hBIMNZf5MRSGiz8lXuvIqLIOq02WIIJzfEa0H1oa5Nei1hToV1 iQI1t0ev8Jm5PEy7RTp3E9TnD2Qyumz5dSEw01Fg86H1ZDpYgCsEHRJbVTK+bRSbiTci 1uqqtNoZYErDwAA1u6WHaPEh5hMxx8VW44aD2INdQbUm/6HLZCwHtp2LR0lrZYxdqGJT 6dUixn6jSxpsBh0Esw49U7AIJ3lpV//i76JM5R5QmcC9Wq4AeG5dyuySGaT50j9l4yTM 846Q== X-Gm-Message-State: AOAM533VXC0w+r64poEHudvU42QxH/K6df2sym3afUaZXAVLo9mV2IXY zfqZoRr8D5b3ilMb/GmCwzdJ60wuMXuH5aO1QSE2NWsZp/1cn/PEX4fH6U5orFfnoqikokkAxBc JbetlR4Kgz1mJbRQ= X-Received: by 2002:a05:600c:21d9:: with SMTP id x25mr12704wmj.145.1604414090574; Tue, 03 Nov 2020 06:34:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJzlVTplgUhn5uNktwrBLUFGSY1jRU5hAmpCQjmumDJbvH5L2Mh+UrjIrVQ8Sbn0IjCYPidcDQ== X-Received: by 2002:a05:600c:21d9:: with SMTP id x25mr12685wmj.145.1604414090391; Tue, 03 Nov 2020 06:34:50 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id y201sm3473669wmd.27.2020.11.03.06.34.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:49 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:48 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 18/38] virtio-iommu: Add notify_flag_changed() memory region callback Message-ID: <20201103142306.71782-19-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Bharat Bhushan , Jean-Philippe Brucker , Eric Auger Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bharat Bhushan Add notify_flag_changed() to notice when memory listeners are added and removed. Acked-by: Eric Auger Signed-off-by: Bharat Bhushan Signed-off-by: Jean-Philippe Brucker Message-Id: <20201030180510.747225-7-jean-philippe@linaro.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-iommu.c | 14 ++++++++++++++ hw/virtio/trace-events | 2 ++ 2 files changed, 16 insertions(+) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 985257c88f..78e07aa40a 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -886,6 +886,19 @@ unlock: qemu_mutex_unlock(&s->mutex); } +static int virtio_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu_mr, + IOMMUNotifierFlag old, + IOMMUNotifierFlag new, + Error **errp) +{ + if (old == IOMMU_NOTIFIER_NONE) { + trace_virtio_iommu_notify_flag_add(iommu_mr->parent_obj.name); + } else if (new == IOMMU_NOTIFIER_NONE) { + trace_virtio_iommu_notify_flag_del(iommu_mr->parent_obj.name); + } + return 0; +} + static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); @@ -1116,6 +1129,7 @@ static void virtio_iommu_memory_region_class_init(ObjectClass *klass, imrc->translate = virtio_iommu_translate; imrc->replay = virtio_iommu_replay; + imrc->notify_flag_changed = virtio_iommu_notify_flag_changed; } static const TypeInfo virtio_iommu_info = { diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index ea3c3b25ad..982d0002a6 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -109,6 +109,8 @@ virtio_iommu_fill_resv_property(uint32_t devid, uint8_t subtype, uint64_t start, virtio_iommu_notify_map(const char *name, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start, uint32_t flags) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64" phys_start=0x%"PRIx64" flags=%d" virtio_iommu_notify_unmap(const char *name, uint64_t virt_start, uint64_t virt_end) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64 virtio_iommu_remap(const char *name, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64" phys_start=0x%"PRIx64 +virtio_iommu_notify_flag_add(const char *name) "add notifier to mr %s" +virtio_iommu_notify_flag_del(const char *name) "del notifier from mr %s" # virtio-mem.c virtio_mem_send_response(uint16_t type) "type=%" PRIu16 From patchwork Tue Nov 3 14:34:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877871 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 D3C8D6A2 for ; Tue, 3 Nov 2020 14:57:03 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 75C4720757 for ; Tue, 3 Nov 2020 14:57:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="X0sjZ1B6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 75C4720757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:56798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxk6-0000PP-Hl for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:57:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxOm-0004di-6b for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20618) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxOk-0006Vm-40 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:34:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414097; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FzlYUeG8X4vs91S4tquZq9KM016eO3pXrdQjhhAV7O0=; b=X0sjZ1B6O+QsqPSsUAYMaARrOcstLNXu5ngZlBRs/sp54+m9FHuW1XVRwswHh36QhRcR7+ EksIxssEqFLJIVJGSKcGpWEK+GYra9jz5fJ8sAIRV40tA7QRgSJX0kIKC/pK8ky9Sqe/BX sy+QlHgfov6b0V/0f37hO+t/if+KaC0= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-429-rN4aTr9gMiaSiCtSdyzBpg-1; Tue, 03 Nov 2020 09:34:54 -0500 X-MC-Unique: rN4aTr9gMiaSiCtSdyzBpg-1 Received: by mail-wm1-f71.google.com with SMTP id 13so4685371wmf.0 for ; Tue, 03 Nov 2020 06:34:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=FzlYUeG8X4vs91S4tquZq9KM016eO3pXrdQjhhAV7O0=; b=QxKfiGDEieXPvmRHng3SATH18IIxNRA5qKjCokM7mLSy0cUI+UsqYcyZl07+s2bMZa dtkXHgx7xwV5LzEV5FIOOKZLSW8hCAbCGAiiK5spzszg7IsgeHr/jXpzkGDqxB641t47 tr4QGVwIYYMQGe4DObwECX7kRNBQCLnqsKeuW3u75OuW6ktg781H6+dB1l5ns2tE13cc acyBPYaYnEi+cj85HPYEzHxD6qTuxTz9U/uVc2h9vGptx32jERYFb6xnMWmbb2BKouPL jE8/kWgjIYNADMH4uXcEwhKr/gC6iM+Roq94EnTayqa9WNJkgrwMHH1vaoArNwehnh/3 4pRw== X-Gm-Message-State: AOAM530FAXL1k8BBpmlQHqtIvPHZGYf1SrSikwGfCbR6VWmLHDexP6UZ p5pzQrnzeQknJufiDhsQ9pvm9+/Xphddq/49daSYN0jG8GYb/Dk+Gj+QmdcFNYwiQ7iKtzMKeVw PORK2Rhb7DxD1R9w= X-Received: by 2002:adf:e3c2:: with SMTP id k2mr26595121wrm.412.1604414093254; Tue, 03 Nov 2020 06:34:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4YGUSg6SxxS2ualczeg2dsuvckXg3veFurfw1d89XtE0NExuWAydXNxhz6h6u5jvhjAyvqw== X-Received: by 2002:adf:e3c2:: with SMTP id k2mr26595101wrm.412.1604414093018; Tue, 03 Nov 2020 06:34:53 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id v6sm3077666wmj.6.2020.11.03.06.34.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:52 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:50 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 19/38] memory: Add interface to set iommu page size mask Message-ID: <20201103142306.71782-20-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Jean-Philippe Brucker , Peter Xu , Eric Auger , Paolo Bonzini , Bharat Bhushan Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bharat Bhushan Allow to set the page size mask supported by an iommu memory region. This enables a vIOMMU to communicate the page size granule supported by an assigned device, on hosts that use page sizes greater than 4kB. Acked-by: Peter Xu Reviewed-by: Eric Auger Signed-off-by: Bharat Bhushan Signed-off-by: Jean-Philippe Brucker Message-Id: <20201030180510.747225-8-jean-philippe@linaro.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/exec/memory.h | 38 ++++++++++++++++++++++++++++++++++++++ softmmu/memory.c | 13 +++++++++++++ 2 files changed, 51 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index aff6ef7605..0f3e6bcd5e 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -397,6 +397,32 @@ struct IOMMUMemoryRegionClass { * @iommu: the IOMMUMemoryRegion */ int (*num_indexes)(IOMMUMemoryRegion *iommu); + + /** + * @iommu_set_page_size_mask: + * + * Restrict the page size mask that can be supported with a given IOMMU + * memory region. Used for example to propagate host physical IOMMU page + * size mask limitations to the virtual IOMMU. + * + * Optional method: if this method is not provided, then the default global + * page mask is used. + * + * @iommu: the IOMMUMemoryRegion + * + * @page_size_mask: a bitmask of supported page sizes. At least one bit, + * representing the smallest page size, must be set. Additional set bits + * represent supported block sizes. For example a host physical IOMMU that + * uses page tables with a page size of 4kB, and supports 2MB and 4GB + * blocks, will set mask 0x40201000. A granule of 4kB with indiscriminate + * block sizes is specified with mask 0xfffffffffffff000. + * + * Returns 0 on success, or a negative error. In case of failure, the error + * object must be created. + */ + int (*iommu_set_page_size_mask)(IOMMUMemoryRegion *iommu, + uint64_t page_size_mask, + Error **errp); }; typedef struct CoalescedMemoryRange CoalescedMemoryRange; @@ -1409,6 +1435,18 @@ int memory_region_iommu_attrs_to_index(IOMMUMemoryRegion *iommu_mr, */ int memory_region_iommu_num_indexes(IOMMUMemoryRegion *iommu_mr); +/** + * memory_region_iommu_set_page_size_mask: set the supported page + * sizes for a given IOMMU memory region + * + * @iommu_mr: IOMMU memory region + * @page_size_mask: supported page size mask + * @errp: pointer to Error*, to store an error if it happens. + */ +int memory_region_iommu_set_page_size_mask(IOMMUMemoryRegion *iommu_mr, + uint64_t page_size_mask, + Error **errp); + /** * memory_region_name: get a memory region's name * diff --git a/softmmu/memory.c b/softmmu/memory.c index 21d533d8ed..71951fe4dc 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1841,6 +1841,19 @@ static int memory_region_update_iommu_notify_flags(IOMMUMemoryRegion *iommu_mr, return ret; } +int memory_region_iommu_set_page_size_mask(IOMMUMemoryRegion *iommu_mr, + uint64_t page_size_mask, + Error **errp) +{ + IOMMUMemoryRegionClass *imrc = IOMMU_MEMORY_REGION_GET_CLASS(iommu_mr); + int ret = 0; + + if (imrc->iommu_set_page_size_mask) { + ret = imrc->iommu_set_page_size_mask(iommu_mr, page_size_mask, errp); + } + return ret; +} + int memory_region_register_iommu_notifier(MemoryRegion *mr, IOMMUNotifier *n, Error **errp) { From patchwork Tue Nov 3 14:34:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877881 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 CA53D92A for ; Tue, 3 Nov 2020 14:59:32 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 84FB120757 for ; Tue, 3 Nov 2020 14:59:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XUJqmSod" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 84FB120757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36800 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxmV-0003t6-K1 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:59:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33274) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxOn-0004hN-PV for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40854) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxOl-0006Wt-RE for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414099; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ERBcIzJjq9q9CekQaOnDD1IPGOplWp3LnON28jdWCRA=; b=XUJqmSod9j/kouwF45ZfM8gR5iVRvoMjD+e40ygQXAJKtP7jslSs5Q8BlWjFTHFG5guwWE FwM/nBHcLlpBlaukp5AGxZyyc/FHVEkStdr7ZIU+40CkJIUPxZqx8fOglRBBXjXHnbYT8y I4gF8FVxq+LpHaA6rH5m5Xo5grKKYLA= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-317-C14vhzHKMuGSyGDO_yAorQ-1; Tue, 03 Nov 2020 09:34:57 -0500 X-MC-Unique: C14vhzHKMuGSyGDO_yAorQ-1 Received: by mail-wm1-f72.google.com with SMTP id y187so1889106wmy.3 for ; Tue, 03 Nov 2020 06:34:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ERBcIzJjq9q9CekQaOnDD1IPGOplWp3LnON28jdWCRA=; b=DjHQk/XGH9j984619wcLfIGd3wSe1TTaJ4qlHGnOkx17znQVN/ElOHiWEdo3YImuN2 GgUxzzMGJDdSCfIs4pcIFnlMe245GEmNaZCs6GpEsI0Gu8Gh2zkrkkIOS17s75wU3mYO iXC3nG9R43wRYWt+cVm5I2whBt4epg0DibESe9b/G5+aA2WfOIG/qh80WbOUp6nzozfF TPtiipjdNnsutVWaZe2ftb9sLzmMNfzJzFJNNe/W1tVa0k1JqmcwvlV89g5Z3YQ/au2j 97vEI6A0YOp1QZh6p9jNjE3DNYFoto4TVb/w7cA2e+fhYVRRt8E4p0DmKy97+s6HzPHf ZoiA== X-Gm-Message-State: AOAM530VjqrTO+/0MVH4OEF5Fp/jnBBIC89Thr9iDyF/V+yAMycCeW53 p9eN7O4HHe4K4qq5WwLXA1oA55EgsGY08nQlGA2v+R/T3CKoXmwpbZ98S0L9FWH4W3X74aJ+SSz eifuXS/1oWW4dEQE= X-Received: by 2002:a1c:f314:: with SMTP id q20mr68057wmq.104.1604414095707; Tue, 03 Nov 2020 06:34:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJzH8Ki+OZRu0zKldRQeSTbtWlJ6LaH0Mb9PhA7MyiLAYbXtj24RrsGQN2ISpmxtBCtWvLI33g== X-Received: by 2002:a1c:f314:: with SMTP id q20mr68044wmq.104.1604414095572; Tue, 03 Nov 2020 06:34:55 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id s188sm3103699wmf.45.2020.11.03.06.34.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:54 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:53 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 20/38] vfio: Set IOMMU page size as per host supported page size Message-ID: <20201103142306.71782-21-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jean-Philippe Brucker , Peter Maydell , Bharat Bhushan , Alex Williamson , Eric Auger Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bharat Bhushan Set IOMMU supported page size mask same as host Linux supported page size mask. Acked-by: Alex Williamson Reviewed-by: Eric Auger Signed-off-by: Bharat Bhushan Signed-off-by: Jean-Philippe Brucker Message-Id: <20201030180510.747225-9-jean-philippe@linaro.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/vfio/common.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index e18ea2cf91..35895b18a6 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -789,6 +789,14 @@ static void vfio_listener_region_add(MemoryListener *listener, int128_get64(llend), iommu_idx); + ret = memory_region_iommu_set_page_size_mask(giommu->iommu, + container->pgsizes, + &err); + if (ret) { + g_free(giommu); + goto fail; + } + ret = memory_region_register_iommu_notifier(section->mr, &giommu->n, &err); if (ret) { From patchwork Tue Nov 3 14:34:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877805 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 EF60792A for ; Tue, 3 Nov 2020 14:42:20 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A59E0223AC for ; Tue, 3 Nov 2020 14:42:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EhoJ5xYK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A59E0223AC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:37556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxVr-0005cN-QG for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:42:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxOr-0004pb-Bo for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52221) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxOp-0006Yf-27 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414102; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=BrWBtHz+T2+mIPkAWH3w+WMghO+0VMpKeuA9wyAHhqM=; b=EhoJ5xYK6FYtf1KOaqhH9lwv68zoT7EhDTSyaszARafQqKzTPMEtd6oa0nKFbUyR+Z+gf/ DkMgGvgBhFJiXzpN9mnmXqm/LaaSP0OW7JA1veUN+p6t8URILDN+9RydAvsJfOdUL1mPku bx5I+yAMajauPesaIcifSEG+2hzPErE= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-524-sVmfvQiKOVS4bnpwP5VoCg-1; Tue, 03 Nov 2020 09:35:00 -0500 X-MC-Unique: sVmfvQiKOVS4bnpwP5VoCg-1 Received: by mail-wr1-f70.google.com with SMTP id t14so7949156wrs.2 for ; Tue, 03 Nov 2020 06:34:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=BrWBtHz+T2+mIPkAWH3w+WMghO+0VMpKeuA9wyAHhqM=; b=a0fQ+PftoKyzbgZqDdKIdGIW6+MY+CC0SREl5/8QvfabmsQUTvNa0DbNuDOdsENRZL H6ro5gef/9AugnfmmNdzYRtk36mUWR19A9K9x7mL27Zmc/Zi/WRW299xjzgMEgxeBewL 9P4498OERdYERJzPki6p8s9t2ynsRdx92jLVJKAzoRELCU2TZ+YS7y3O7zo8XC0/7new Ty2w/Ji1+g9Si9eRY3JIj9cV4HDUC5djGUyZx3J1UGau1us+waeqzzL3E7eSyuB8xI06 t+l7d+LZghAurxp3P+3xQ621lFGAsPg0sDqnz6HkBkw9V1Wdu1UCE6dlGzsfsyJ1cXQ4 DSXg== X-Gm-Message-State: AOAM531akPs1Ub6lUh3WRNy1wRJi4LeD+TrrHCcRDX9wHqdcATYkUK+Z gCgN+GjFULIJhryvajgauXb8/IlEN5KyZDB/uaRVKfWl5RFUKQforGN0z1HrWqh5CIRp8N9qL+C bLI3FksAeziGicEg= X-Received: by 2002:a5d:688c:: with SMTP id h12mr27314581wru.92.1604414098222; Tue, 03 Nov 2020 06:34:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxk22sc+a5AT/ZGrcRlxRFIpJidEJYI+lMT9I4nycNrc7dJU+9sFphQJ1FjsDaZf2WX0Q6mQ== X-Received: by 2002:a5d:688c:: with SMTP id h12mr27314565wru.92.1604414098039; Tue, 03 Nov 2020 06:34:58 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id w11sm3358061wmg.36.2020.11.03.06.34.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:57 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:55 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 21/38] virtio-iommu: Set supported page size mask Message-ID: <20201103142306.71782-22-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Bharat Bhushan , Eric Auger , Jean-Philippe Brucker Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bharat Bhushan The virtio-iommu device can deal with arbitrary page sizes for virtual endpoints, but for endpoints assigned with VFIO it must follow the page granule used by the host IOMMU driver. Implement the interface to set the vIOMMU page size mask, called by VFIO for each endpoint. We assume that all host IOMMU drivers use the same page granule (the host page granule). Override the page_size_mask field in the virtio config space. Signed-off-by: Bharat Bhushan Signed-off-by: Jean-Philippe Brucker Message-Id: <20201030180510.747225-10-jean-philippe@linaro.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-iommu.c | 50 ++++++++++++++++++++++++++++++++++++++++ hw/virtio/trace-events | 1 + 2 files changed, 51 insertions(+) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 78e07aa40a..fc5c75d693 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -899,6 +899,55 @@ static int virtio_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu_mr, return 0; } +/* + * The default mask (TARGET_PAGE_MASK) is the smallest supported guest granule, + * for example 0xfffffffffffff000. When an assigned device has page size + * restrictions due to the hardware IOMMU configuration, apply this restriction + * to the mask. + */ +static int virtio_iommu_set_page_size_mask(IOMMUMemoryRegion *mr, + uint64_t new_mask, + Error **errp) +{ + IOMMUDevice *sdev = container_of(mr, IOMMUDevice, iommu_mr); + VirtIOIOMMU *s = sdev->viommu; + uint64_t cur_mask = s->config.page_size_mask; + + trace_virtio_iommu_set_page_size_mask(mr->parent_obj.name, cur_mask, + new_mask); + + if ((cur_mask & new_mask) == 0) { + error_setg(errp, "virtio-iommu page mask 0x%"PRIx64 + " is incompatible with mask 0x%"PRIx64, cur_mask, new_mask); + return -1; + } + + /* + * After the machine is finalized, we can't change the mask anymore. If by + * chance the hotplugged device supports the same granule, we can still + * accept it. Having a different masks is possible but the guest will use + * sub-optimal block sizes, so warn about it. + */ + if (qdev_hotplug) { + int new_granule = ctz64(new_mask); + int cur_granule = ctz64(cur_mask); + + if (new_granule != cur_granule) { + error_setg(errp, "virtio-iommu page mask 0x%"PRIx64 + " is incompatible with mask 0x%"PRIx64, cur_mask, + new_mask); + return -1; + } else if (new_mask != cur_mask) { + warn_report("virtio-iommu page mask 0x%"PRIx64 + " does not match 0x%"PRIx64, cur_mask, new_mask); + } + return 0; + } + + s->config.page_size_mask &= new_mask; + return 0; +} + static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); @@ -1130,6 +1179,7 @@ static void virtio_iommu_memory_region_class_init(ObjectClass *klass, imrc->translate = virtio_iommu_translate; imrc->replay = virtio_iommu_replay; imrc->notify_flag_changed = virtio_iommu_notify_flag_changed; + imrc->iommu_set_page_size_mask = virtio_iommu_set_page_size_mask; } static const TypeInfo virtio_iommu_info = { diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 982d0002a6..2060a144a2 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -109,6 +109,7 @@ virtio_iommu_fill_resv_property(uint32_t devid, uint8_t subtype, uint64_t start, virtio_iommu_notify_map(const char *name, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start, uint32_t flags) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64" phys_start=0x%"PRIx64" flags=%d" virtio_iommu_notify_unmap(const char *name, uint64_t virt_start, uint64_t virt_end) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64 virtio_iommu_remap(const char *name, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64" phys_start=0x%"PRIx64 +virtio_iommu_set_page_size_mask(const char *name, uint64_t old, uint64_t new) "mr=%s old_mask=0x%"PRIx64" new_mask=0x%"PRIx64 virtio_iommu_notify_flag_add(const char *name) "add notifier to mr %s" virtio_iommu_notify_flag_del(const char *name) "del notifier from mr %s" From patchwork Tue Nov 3 14:34:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877815 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 D66F86A2 for ; Tue, 3 Nov 2020 14:45:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7F0EB2242C for ; Tue, 3 Nov 2020 14:45:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Gkfj6NfS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7F0EB2242C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxYn-0000tE-Hn for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:45:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33340) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxOv-0004wj-1q for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53086) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxOs-0006Zz-Fq for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414105; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LJXuyrvNWCkVg8E30mdyIeR8YxS8TNHSTHiQCqv2NOU=; b=Gkfj6NfS8YvtHcX5wpmrkpsOOJfPtOKATGtDXKRJeiWARGgjf05wfWXOpQ11OE/2JuGkQW rNK1gSn/MdDGvapFr16sOEHzRSj413Axj2cg2E0x5EWW2uKDN8MyEclY2FT1zOtafG4p5b EmL3YQxXw4GiSyZ71NqMuo18lu6WUbQ= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-371-4Unm8fPeOK2__Uo-8rIyuA-1; Tue, 03 Nov 2020 09:35:01 -0500 X-MC-Unique: 4Unm8fPeOK2__Uo-8rIyuA-1 Received: by mail-wr1-f69.google.com with SMTP id j15so7902483wrd.16 for ; Tue, 03 Nov 2020 06:35:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=LJXuyrvNWCkVg8E30mdyIeR8YxS8TNHSTHiQCqv2NOU=; b=qhJacq3fdodejOaERngF4l+RmS/DhgDgvzuzuzNb6a9vD5dKBuRvyj2AwZnGJc2nEf bdBSvrvAAbSTFGZP4x7BGF/soaaVfuqViplRwVwfxUZK3tFfdFer7HOUYYXche2xSPTa zeCRvXGv3W98pLtDAdUXCGGB3CW2alwv9GE8ij70RUuYY9EfTiLRWHn/JChBxTGARtz0 wqcNpr8u/wufD/41dlV7qmnqid6sdY7v6eE1E12Eeh5ZzukMAo5LHJQ56qkkr7+XUeec 9RDeui6ru0yfmrVLlGN35YI4/JeF4ggGhWfr86GKv9165xhonyIBnlsrrVmw78SUuBHK Y5aw== X-Gm-Message-State: AOAM530KzFtwGPVp7a4UQ9NNx5gsGVLtkrj7KSxONgZSZqzB+4m3P+ds HUegJeo+6aqkFnqEtdSpeqKxons5u56X+amskD2Up4GhaCgddJLRS6a6HEMaOrS0pPfCfuZnjwF essbL3DUe9CV3W4k= X-Received: by 2002:adf:a501:: with SMTP id i1mr26015669wrb.162.1604414100539; Tue, 03 Nov 2020 06:35:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJzohVDXeJgY2Uzuxu26uTMiTy5ypxNWqaQkgURHFuYyTC+1Q8EDjSpZmPBBwVGslSigcWGcdQ== X-Received: by 2002:adf:a501:: with SMTP id i1mr26015650wrb.162.1604414100395; Tue, 03 Nov 2020 06:35:00 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id k84sm3135206wmf.42.2020.11.03.06.34.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:34:59 -0800 (PST) Date: Tue, 3 Nov 2020 09:34:58 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 22/38] vfio: Don't issue full 2^64 unmap Message-ID: <20201103142306.71782-23-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Alex Williamson , Eric Auger , Jean-Philippe Brucker Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Jean-Philippe Brucker IOMMUs may declare memory regions spanning from 0 to UINT64_MAX. When attempting to deal with such region, vfio_listener_region_del() passes a size of 2^64 to int128_get64() which throws an assertion failure. Even ignoring this, the VFIO_IOMMU_DMA_MAP ioctl cannot handle this size since the size field is 64-bit. Split the request in two. Acked-by: Alex Williamson Reviewed-by: Eric Auger Signed-off-by: Jean-Philippe Brucker Message-Id: <20201030180510.747225-11-jean-philippe@linaro.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/vfio/common.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 35895b18a6..7e9d1a17b7 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -950,6 +950,17 @@ static void vfio_listener_region_del(MemoryListener *listener, } if (try_unmap) { + if (llsize == int128_2_64()) { + /* The unmap ioctl doesn't accept a full 64-bit span. */ + llsize = int128_rshift(llsize, 1); + ret = vfio_dma_unmap(container, iova, int128_get64(llsize), NULL); + if (ret) { + error_report("vfio_dma_unmap(%p, 0x%"HWADDR_PRIx", " + "0x%"HWADDR_PRIx") = %d (%m)", + container, iova, int128_get64(llsize), ret); + } + iova += int128_get64(llsize); + } ret = vfio_dma_unmap(container, iova, int128_get64(llsize), NULL); if (ret) { error_report("vfio_dma_unmap(%p, 0x%"HWADDR_PRIx", " From patchwork Tue Nov 3 14:35:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877891 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 85EA9921 for ; Tue, 3 Nov 2020 15:02:29 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 246B3206DB for ; Tue, 3 Nov 2020 15:02:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Oge5vED8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 246B3206DB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:45202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxpM-0007cU-4m for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 10:02:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33344) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxOw-0004zL-AL for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49845) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxOt-0006a4-10 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414106; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Try6I8+Gzp362j90+uCp08fdMyiL5wC2Bsqj8twh+n4=; b=Oge5vED8/T0NSBVeS0SBz8N0ldebBL6XFuz7ghOQbiDew7duBjeKvNIcu2lTB4whFOTq0x LJLqvGkzGJC9PsqNoe5whChcIppgNTq6GBF0FirXtE9nrqNOPDJ+aoxuvyoL9GEg5z8sqv JBxIHC9L3B2zvXV0EOGV7X7IXjZMcY4= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-193-yoGiQsDEOwiPx8rr2Hn26g-1; Tue, 03 Nov 2020 09:35:04 -0500 X-MC-Unique: yoGiQsDEOwiPx8rr2Hn26g-1 Received: by mail-wr1-f69.google.com with SMTP id j15so7902518wrd.16 for ; Tue, 03 Nov 2020 06:35:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Try6I8+Gzp362j90+uCp08fdMyiL5wC2Bsqj8twh+n4=; b=mdN21yfwmoQm6/HAMoCNmYI5T7hvena4F267+Mw1UiBTi0sc+T+rMoax+8+kKFo4Ay 7XbVYlW4L01IwuHbPBtvoo6xhdd6FNs1refU+dlLazfJUx1PvRdMK54+tLGyTLlXHBvl wVcUXZhopoHvHxxFf9C9Vj3YCd+eF5aaSZEOEajzhFN3XeJJ/soR34F19rSoYxAPD1Nj nN4kQaspgfe+QV2ZwSdjfdfYU+dTt4w/LWmGg6mYiZofjITKUJUdmgpmCW0jlOokzgYP J9UJGuFkQZD1iasms0TrDXtVLhMYlEosX4vNZMiOuRs2Ot6pGeACvgKCYM9L1RBJ+W4m FRkA== X-Gm-Message-State: AOAM5334mzRfQkFlvHvneZSTq87xJ3tShIA/DgswMhDxyvzvwynevq35 yYBoimV7Cfo9D0ROgH/tyVySdYHozW1O1mROF4c4Jz3aIhjws4Lw8xslBeXe+K0kdgbvBvVWA/o c3id520ZAn8X2PCE= X-Received: by 2002:a7b:c3d5:: with SMTP id t21mr36861wmj.37.1604414102846; Tue, 03 Nov 2020 06:35:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJza4rrcu/xR+QjdM8GsHhwuJ9vtUSLavliR20kgMLMjA+Tj66AKFQ72Q6aAv3V9GyDplIH1Sw== X-Received: by 2002:a7b:c3d5:: with SMTP id t21mr36844wmj.37.1604414102704; Tue, 03 Nov 2020 06:35:02 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id v123sm3205562wme.7.2020.11.03.06.35.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:35:02 -0800 (PST) Date: Tue, 3 Nov 2020 09:35:00 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 23/38] vhost-vdpa: Add qemu_close in vhost_vdpa_cleanup Message-ID: <20201103142306.71782-24-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Jason Wang , Cindy Lu Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Cindy Lu fix the bug that fd will still open after the cleanup Signed-off-by: Cindy Lu Message-Id: <20201016030909.9522-1-lulu@redhat.com> Acked-by: Jason Wang Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- net/vhost-vdpa.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 99c476db8c..fe659ec9e2 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -145,6 +145,10 @@ static void vhost_vdpa_cleanup(NetClientState *nc) g_free(s->vhost_net); s->vhost_net = NULL; } + if (s->vhost_vdpa.device_fd >= 0) { + qemu_close(s->vhost_vdpa.device_fd); + s->vhost_vdpa.device_fd = -1; + } } static bool vhost_vdpa_has_vnet_hdr(NetClientState *nc) From patchwork Tue Nov 3 14:35:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877821 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 398C792A for ; Tue, 3 Nov 2020 14:48:33 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EA8792242C for ; Tue, 3 Nov 2020 14:48:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="X2d96dbv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EA8792242C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:55402 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxbr-0004lE-QP for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:48:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33418) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxP3-0005FN-7k for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:54282) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxP1-0006dG-AV for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414114; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=MaK8aBvBSiaUINk0iflL/mAr7Ti2mM7e4TQ+bKVJ1uk=; b=X2d96dbvSj6sVPU6BrjstpfBNaINC4sef4rd6mGI+OIyLqcBonsWxfKlLqNX9tULL5ZpJL Fx4PMLZuv9+4oqlUmCSXkqqDDkBbrRw1GGfOQjdYp+j0jlUWGG/wN3kMvtSeGVLvimy/0X vDJ/WAOn9vYjbCEcw/EAmHNNRZ6FiUw= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-44-nrUvLGhlMpCUMssc9-BaRA-1; Tue, 03 Nov 2020 09:35:07 -0500 X-MC-Unique: nrUvLGhlMpCUMssc9-BaRA-1 Received: by mail-wm1-f69.google.com with SMTP id o19so4683045wme.2 for ; Tue, 03 Nov 2020 06:35:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=MaK8aBvBSiaUINk0iflL/mAr7Ti2mM7e4TQ+bKVJ1uk=; b=pLskcOu0fa4by2r4BuNV/Tbx8yY3YHYm5lA3wXG9p9vTzOO1kU8/Ct3bTggiiW2gu0 4eqdpXRVJWwcgUXCPJ/QneEayMCVohbNPh7czOskqGi8whbYRTdm7dSD28HzZLgoU0Mx EU/sjYlUvFR9w8OIrI/RBlELo6FsAtjBG0trcPPZyTjg3W37ExaQGeUJOiKVyudcUcgc DhkD9eUoMQ60yxecX04/jyE4rs3WOtDzV3S/haCNGQ2iIQ2VZf3vskzpG4A53pRHB4N9 v6oEpX6oJ7MkhRjkAMt+n7aNmZo4eiG3/wMLG1174lG5hte6E9CMQtkkiZQf3enP178V S39g== X-Gm-Message-State: AOAM533lQ7nYnAqCyi8n1EGC3A66uyh2UM8d3dv7jjqIxkC27bOnFLDr h1xUwbB6gp7/ABmKBnPORMq+OKXG5u6s9cZdDbDE0j3knYFR36aygXuxmCBi0SHXkoDUNfY7SQy HAmeYShdNeGO58rk= X-Received: by 2002:adf:804e:: with SMTP id 72mr15809440wrk.114.1604414105281; Tue, 03 Nov 2020 06:35:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJwTQAOm1DKZcntZ9rNaostJDtdyinpLRrrbgx3yPrVUc0zTo8Z5s30M303N7/zcF8/H0ZsmeA== X-Received: by 2002:adf:804e:: with SMTP id 72mr15809425wrk.114.1604414105142; Tue, 03 Nov 2020 06:35:05 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id m21sm1702974wmi.3.2020.11.03.06.35.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:35:04 -0800 (PST) Date: Tue, 3 Nov 2020 09:35:02 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 24/38] net: Add vhost-vdpa in show_netdevs() Message-ID: <20201103142306.71782-25-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Jason Wang , Cindy Lu Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Cindy Lu Fix the bug that while Check qemu supported netdev, there is no vhost-vdpa Signed-off-by: Cindy Lu Message-Id: <20201016030909.9522-2-lulu@redhat.com> Acked-by: Jason Wang Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- net/net.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/net.c b/net/net.c index 7a2a0fb5ac..794c652282 100644 --- a/net/net.c +++ b/net/net.c @@ -1049,6 +1049,9 @@ static void show_netdevs(void) #endif #ifdef CONFIG_POSIX "vhost-user", +#endif +#ifdef CONFIG_VHOST_VDPA + "vhost-vdpa", #endif }; From patchwork Tue Nov 3 14:35:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877887 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 1DB85921 for ; Tue, 3 Nov 2020 15:01:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BB645206CB for ; Tue, 3 Nov 2020 15:01:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="C8i8S/Ne" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BB645206CB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:42296 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxoV-0006O7-OD for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 10:01:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34348) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxRm-0008SL-1z for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:38:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21608) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxRk-0007eC-3m for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:38:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414283; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=oxFgfij5tGa7wsPJMg6guJqSTCSDLHe43Ge56aYH6Hc=; b=C8i8S/NewW1T8m1wUQZq1XI+plyexXQ0dv7q6dCrKBqKID6mv0V5VP9nPAQCF7eZPxIixb lyK0gLH+9zaSyJxyzU8pNK+6NL5crF9GV1GXqbWhRJlWSQ6f59+kcDNecd5NFJ9MqwB/Oc Ik5N6DLgBnRKASp4CurMI3KvNeiUb00= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-18-at3wqhQ0NLif2AUus-734w-1; Tue, 03 Nov 2020 09:35:09 -0500 X-MC-Unique: at3wqhQ0NLif2AUus-734w-1 Received: by mail-wr1-f69.google.com with SMTP id j15so7902599wrd.16 for ; Tue, 03 Nov 2020 06:35:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=oxFgfij5tGa7wsPJMg6guJqSTCSDLHe43Ge56aYH6Hc=; b=L+B1MhXzdPUu6Hx821V0zujW9MECfhhoBLNG2MMWmYuAOywPs/2LsFbrXd+dv9FKTe IyaT0UWgzuv1jU3Y0iRXz3OpKhX0DSv0qUiFueCIkY3ZRbqVV7RATdBvZoiMjYQ0DAHF KqnEHB2jpPAAEMfegIJknVb3TOG1y6O+8knu/8NXSyDF+Kl+Wo53tVm+dhuTobfoH7nH +6jdhc/i+sL50DMg28Hd/S8SxwaSM8WBK651IA25AE4Bn4HKNDemoy2E3g7qSWbDBiJ5 FIegz8D3FM5SHpz25VjxUbyhQQ5T5kO4w7a2FbYIyYCeFNzWsd38H59G55H8u/jPyTw6 j0lA== X-Gm-Message-State: AOAM531F4dw1eeWQwWuMx1iDoB7oMz/OpcpPimsPZpM7iDPe0oOcxYcL 5CjOwNbIRVVL8UkTu3sKbCLgDTQjBmyFy7wOXNscw+qdKlA6derb7Mx09V5qjuc/ucoLDoMZ0kl 0tpO6mrcyyG12QKI= X-Received: by 2002:a1c:4d4:: with SMTP id 203mr9851wme.153.1604414107910; Tue, 03 Nov 2020 06:35:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJw/D/b40QJ0pHTZNqKXjbVDdRAZjhK7ooCtOmACtwoJyaIglUuFToAG3zLzZG61sGw505MbHw== X-Received: by 2002:a1c:4d4:: with SMTP id 203mr9829wme.153.1604414107749; Tue, 03 Nov 2020 06:35:07 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id n4sm10608825wrv.13.2020.11.03.06.35.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:35:07 -0800 (PST) Date: Tue, 3 Nov 2020 09:35:05 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 25/38] Revert "vhost-blk: set features before setting inflight feature" Message-ID: <20201103142306.71782-26-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-block@nongnu.org, Jin Yu , Max Reitz , Stefan Hajnoczi , Raphael Norwitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Stefan Hajnoczi This reverts commit adb29c027341ba095a3ef4beef6aaef86d3a520e. The commit broke -device vhost-user-blk-pci because the vhost_dev_prepare_inflight() function it introduced segfaults in vhost_dev_set_features() when attempting to access struct vhost_dev's vdev pointer before it has been assigned. To reproduce the segfault simply launch a vhost-user-blk device with the contrib vhost-user-blk device backend: $ build/contrib/vhost-user-blk/vhost-user-blk -s /tmp/vhost-user-blk.sock -r -b /var/tmp/foo.img $ build/qemu-system-x86_64 \ -device vhost-user-blk-pci,id=drv0,chardev=char1,addr=4.0 \ -object memory-backend-memfd,id=mem,size=1G,share=on \ -M memory-backend=mem,accel=kvm \ -chardev socket,id=char1,path=/tmp/vhost-user-blk.sock Segmentation fault (core dumped) Cc: Jin Yu Cc: Raphael Norwitz Cc: Michael S. Tsirkin Signed-off-by: Stefan Hajnoczi Message-Id: <20201102165709.232180-1-stefanha@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/vhost.h | 1 - hw/block/vhost-user-blk.c | 6 ------ hw/virtio/vhost.c | 18 ------------------ 3 files changed, 25 deletions(-) diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 839bfb153c..94585067f7 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -141,7 +141,6 @@ void vhost_dev_reset_inflight(struct vhost_inflight *inflight); void vhost_dev_free_inflight(struct vhost_inflight *inflight); void vhost_dev_save_inflight(struct vhost_inflight *inflight, QEMUFile *f); int vhost_dev_load_inflight(struct vhost_inflight *inflight, QEMUFile *f); -int vhost_dev_prepare_inflight(struct vhost_dev *hdev); int vhost_dev_set_inflight(struct vhost_dev *dev, struct vhost_inflight *inflight); int vhost_dev_get_inflight(struct vhost_dev *dev, uint16_t queue_size, diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index f67b29bbf3..a076b1e54d 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -131,12 +131,6 @@ static int vhost_user_blk_start(VirtIODevice *vdev) s->dev.acked_features = vdev->guest_features; - ret = vhost_dev_prepare_inflight(&s->dev); - if (ret < 0) { - error_report("Error set inflight format: %d", -ret); - goto err_guest_notifiers; - } - if (!s->inflight->addr) { ret = vhost_dev_get_inflight(&s->dev, s->queue_size, s->inflight); if (ret < 0) { diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index f2482378c6..79b2be20df 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1645,24 +1645,6 @@ int vhost_dev_load_inflight(struct vhost_inflight *inflight, QEMUFile *f) return 0; } -int vhost_dev_prepare_inflight(struct vhost_dev *hdev) -{ - int r; - - if (hdev->vhost_ops->vhost_get_inflight_fd == NULL || - hdev->vhost_ops->vhost_set_inflight_fd == NULL) { - return 0; - } - - r = vhost_dev_set_features(hdev, hdev->log_enabled); - if (r < 0) { - VHOST_OPS_DEBUG("vhost_dev_prepare_inflight failed"); - return r; - } - - return 0; -} - int vhost_dev_set_inflight(struct vhost_dev *dev, struct vhost_inflight *inflight) { From patchwork Tue Nov 3 14:35:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877813 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 74B446A2 for ; Tue, 3 Nov 2020 14:45:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 081452242F for ; Tue, 3 Nov 2020 14:45:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SuYWGuc3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 081452242F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:45954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxYd-0000jf-33 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:45:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33464) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxP5-0005L3-Mj for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:24875) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxP3-0006el-Dn for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414116; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ay6G7kYGtMwl+/IxEdsu272p/jXvwydr69tjR0/ihX0=; b=SuYWGuc3wXTPPJ6gB72QiQQO6rldnnf4pKILpm9/2XKkEFzMqWekJpuc1tEOAoCzny3hWx Gj6sOKQbsUOE267iyAYGRdIiibBrA1dpBxB7aBTgth6SwnYmKz9qsalxckhOfRoaI9T+ly lH76N6QK+mRrbJkno01mf4dBk3T92i8= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-327-Q7uTG_fWOzyF1Ro24Aj6Zw-1; Tue, 03 Nov 2020 09:35:12 -0500 X-MC-Unique: Q7uTG_fWOzyF1Ro24Aj6Zw-1 Received: by mail-wm1-f70.google.com with SMTP id 13so4685667wmf.0 for ; Tue, 03 Nov 2020 06:35:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ay6G7kYGtMwl+/IxEdsu272p/jXvwydr69tjR0/ihX0=; b=C5poTBvvwCbuG97d3X64tW/0VzWF0p/1XbgtnNmmFPIGjsHc4MgmV7OPWd1+Od3u0h rw654RQ0+6iZd3RYwBNcO0RedM7sBapx5+21kGwvyx3W5JpDHanEGimKKsOK31D/UY9D ZAD4EbNAzS6hoDA6l5633RDLB4svabDovjk7yZKdqIgd2OpCUp8TAfZtVnD9RS8hxRNK 2eoEpPl88E4ZxEFLFpTd4YBbyru0vBtpslMJfU2aitqXq+w+gjrGD4zPZBnw8Zz1tg4t dXYeuD45Fh3Oka+7UG48pCHxRA9RZjvQipIf/3wVZTPqayqjvUyBljX/GM9wWC+Z1PIg 1zMw== X-Gm-Message-State: AOAM532DZiwYyLNRL1o+e9XCXdcAMtGx+ZOJBzNHjx9Qy4E5+GwZEAXg gT3HOnIQdh9iTV40MFgJvYvL40OX3NGgyx22yerjGILArDNDv9ZBCbQIyqk9xETDm99QvG+xwtV 5soCmw+vrZ+Xsies= X-Received: by 2002:a1c:750b:: with SMTP id o11mr94075wmc.32.1604414110652; Tue, 03 Nov 2020 06:35:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJx1hcFbfc36uCTcXTH0RBujb6aH3ehkwq4gFuYX+bJGZ0LL5T5YwBzGhm5W/v3/CIcSCjAnQA== X-Received: by 2002:a1c:750b:: with SMTP id o11mr94059wmc.32.1604414110496; Tue, 03 Nov 2020 06:35:10 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id 66sm3321234wmb.3.2020.11.03.06.35.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:35:09 -0800 (PST) Date: Tue, 3 Nov 2020 09:35:08 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 26/38] vhost-blk: set features before setting inflight feature Message-ID: <20201103142306.71782-27-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-block@nongnu.org, Jin Yu , Max Reitz , Raphael Norwitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Jin Yu Virtqueue has split and packed, so before setting inflight, you need to inform the back-end virtqueue format. Signed-off-by: Jin Yu Acked-by: Raphael Norwitz Message-Id: <20201103123617.28256-1-jin.yu@intel.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/vhost.h | 1 + hw/block/vhost-user-blk.c | 6 ++++++ hw/virtio/vhost.c | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 94585067f7..4a8bc75415 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -141,6 +141,7 @@ void vhost_dev_reset_inflight(struct vhost_inflight *inflight); void vhost_dev_free_inflight(struct vhost_inflight *inflight); void vhost_dev_save_inflight(struct vhost_inflight *inflight, QEMUFile *f); int vhost_dev_load_inflight(struct vhost_inflight *inflight, QEMUFile *f); +int vhost_dev_prepare_inflight(struct vhost_dev *hdev, VirtIODevice *vdev); int vhost_dev_set_inflight(struct vhost_dev *dev, struct vhost_inflight *inflight); int vhost_dev_get_inflight(struct vhost_dev *dev, uint16_t queue_size, diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index a076b1e54d..2dd3d93ca0 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -131,6 +131,12 @@ static int vhost_user_blk_start(VirtIODevice *vdev) s->dev.acked_features = vdev->guest_features; + ret = vhost_dev_prepare_inflight(&s->dev, vdev); + if (ret < 0) { + error_report("Error set inflight format: %d", -ret); + goto err_guest_notifiers; + } + if (!s->inflight->addr) { ret = vhost_dev_get_inflight(&s->dev, s->queue_size, s->inflight); if (ret < 0) { diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 79b2be20df..614ccc2bcb 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1645,6 +1645,26 @@ int vhost_dev_load_inflight(struct vhost_inflight *inflight, QEMUFile *f) return 0; } +int vhost_dev_prepare_inflight(struct vhost_dev *hdev, VirtIODevice *vdev) +{ + int r; + + if (hdev->vhost_ops->vhost_get_inflight_fd == NULL || + hdev->vhost_ops->vhost_set_inflight_fd == NULL) { + return 0; + } + + hdev->vdev = vdev; + + r = vhost_dev_set_features(hdev, hdev->log_enabled); + if (r < 0) { + VHOST_OPS_DEBUG("vhost_dev_prepare_inflight failed"); + return r; + } + + return 0; +} + int vhost_dev_set_inflight(struct vhost_dev *dev, struct vhost_inflight *inflight) { From patchwork Tue Nov 3 14:35:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877827 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 3E73A6A2 for ; Tue, 3 Nov 2020 14:49:40 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E051A22370 for ; Tue, 3 Nov 2020 14:49:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NTob9/nV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E051A22370 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:60718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxcw-0006ul-Us for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:49:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33486) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxP6-0005OH-V8 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58198) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxP3-0006ej-As for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414116; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=APdAnMGOimWpi0/lmUkQSWdNUl1kK18oif2GgMOHc/o=; b=NTob9/nV/jdls7qUfEFYyHigmUGCLRwmfJskk5YG1at3AryajlErEqlRx2OPhx+nC1o/T6 zGbeHcXRPs77NQnOg17I7hmQTZEHXWt2vmJDkNAgRD7eH47uzMprKevYRDXDaoTIRir9fZ 4uZGuFh6VSr/1osP+XIsmIfWjLMfI8k= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-549-l0nhv9nZMQ-ds_GTRLbxQA-1; Tue, 03 Nov 2020 09:35:15 -0500 X-MC-Unique: l0nhv9nZMQ-ds_GTRLbxQA-1 Received: by mail-wm1-f72.google.com with SMTP id z62so18603wmb.1 for ; Tue, 03 Nov 2020 06:35:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=APdAnMGOimWpi0/lmUkQSWdNUl1kK18oif2GgMOHc/o=; b=gQuBTpmuvma+Zi9uiLBgCxxx4Utu50L3Vlk634BlVgTXKxy6IRXc6snf/8uzcF0TAU EbzcYBNi3WYZzmtEw8qEGyMjkLiITJuiYxqU4N9p7RR0775Cve06a9GzbhW1dyjtZ5gF KUxhz8JDF3DlmHo2NdFPd3fbhl1Iec75w6eiBvter4jCuWQMj63q1TS/vDIYN6NtKSgY 07ClaLc1pEwEPtRAEHcGTHoXY5bIYLzA5M1XItnn8dcfML+S9psoG8Y+rPLoF5HVfuqZ awR1JaefnrPnLvT+ZTDa2N5ncsv3B8KAJoqtJ4gUIreAbzGrqwd8Pdp991MRaFNYEdEJ lecA== X-Gm-Message-State: AOAM533K8vczVG+fKachjmEEdAjiz3v+K4GRiI+f6xPJQyB8ME8eXeEi h7O1aM5VfS+tA+osH4bdI0bzszhWSBBfvlT2MkzowjP5eja9Ehl/0DCgJEUUUeCtfU1HnVeUMmc txM9+Awc80wsPJsU= X-Received: by 2002:a5d:4409:: with SMTP id z9mr26083329wrq.236.1604414113245; Tue, 03 Nov 2020 06:35:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJxZR2kKqcuddZ/U6aOOxHKUCf2fG112fCduIj9t2zuR4ymWycluttXqA0FkMzP7RA0aJ63HAw== X-Received: by 2002:a5d:4409:: with SMTP id z9mr26083314wrq.236.1604414113101; Tue, 03 Nov 2020 06:35:13 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id c17sm3016007wml.14.2020.11.03.06.35.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:35:12 -0800 (PST) Date: Tue, 3 Nov 2020 09:35:10 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 27/38] libvhost-user: follow QEMU comment style Message-ID: <20201103142306.71782-28-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Marc-Andr=C3=A9?= Lureau , "Dr. David Alan Gilbert" , Stefan Hajnoczi , Raphael Norwitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Stefan Hajnoczi Signed-off-by: Stefan Hajnoczi Message-Id: <20201027173528.213464-2-stefanha@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- contrib/libvhost-user/libvhost-user.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/contrib/libvhost-user/libvhost-user.h b/contrib/libvhost-user/libvhost-user.h index 3bbeae8587..a1539dbb69 100644 --- a/contrib/libvhost-user/libvhost-user.h +++ b/contrib/libvhost-user/libvhost-user.h @@ -392,7 +392,8 @@ struct VuDev { bool broken; uint16_t max_queues; - /* @read_msg: custom method to read vhost-user message + /* + * @read_msg: custom method to read vhost-user message * * Read data from vhost_user socket fd and fill up * the passed VhostUserMsg *vmsg struct. @@ -409,15 +410,19 @@ struct VuDev { * */ vu_read_msg_cb read_msg; - /* @set_watch: add or update the given fd to the watch set, - * call cb when condition is met */ + + /* + * @set_watch: add or update the given fd to the watch set, + * call cb when condition is met. + */ vu_set_watch_cb set_watch; /* @remove_watch: remove the given fd from the watch set */ vu_remove_watch_cb remove_watch; - /* @panic: encountered an unrecoverable error, you may try to - * re-initialize */ + /* + * @panic: encountered an unrecoverable error, you may try to re-initialize + */ vu_panic_cb panic; const VuDevIface *iface; From patchwork Tue Nov 3 14:35:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877823 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 8A6486A2 for ; Tue, 3 Nov 2020 14:49:02 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 494532242F for ; Tue, 3 Nov 2020 14:49:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dStcT2hP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 494532242F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:57296 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxcL-0005Y3-6E for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:49:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33510) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxP9-0005T8-08 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:34018) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxP6-0006j1-Ul for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414120; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FOR/bv25dGPFB9FnzIFOxW/ObDgDZns8YprwAzRry/Y=; b=dStcT2hP7txkJUbPyH28UvBmAkbdqgIvuVqr0jIveYiHMtwDXVDh89hbWn9xmtT4DIG0/S PJKwHdOVszFsV29itfs1lNfXfaSeP53777Qs+iFJvpDUerlafXLO4bc1WY6r8K8w98iYth X4h0dvFiJlXSyNgeTaOXKcp4WKq7adI= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-155-NTS9-Xv3NsK3MlXb6swmeg-1; Tue, 03 Nov 2020 09:35:18 -0500 X-MC-Unique: NTS9-Xv3NsK3MlXb6swmeg-1 Received: by mail-wm1-f70.google.com with SMTP id z62so18676wmb.1 for ; Tue, 03 Nov 2020 06:35:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=FOR/bv25dGPFB9FnzIFOxW/ObDgDZns8YprwAzRry/Y=; b=YzL7dy7rucgyEV0baMmvYXxZ3/NODbdbuTHcrtajgFUdbg5etVq4O7IPpA5bpTud/L aVAVWNWVlCho0ow6hb48I3NDFcm0MbH60xsESz/UQKoWpqY5hcTHfKRvqc6QKt/eXPZW l4HDaosmBtXnd9SF8y7lKOTnWokVBy24O4IMBkd0gX1R+fOn8GeXs8cUZB5ZyghBA/pb Zj8eR5neMiPayhqE4TOFKUt8iyV4dqXSnAAXt6aNrB4wHRubd9ySbNvRs+wkxaNyrFGz WTq+o0pRtJjWR4DH6+YlJo6lYQPk22x87SQYe/lcB0C1lPpq8UoBTu11PjwNYyV44SUV KXng== X-Gm-Message-State: AOAM532OmZUK8+1ByVZeqmv1eZ5YMfm9bEsdvBHKKSIIrDKvNfQaT0nR 4+aV39RKaF+bJjA85jLsNIzWy7bKeUV6qbxBeW+O1c1u8QiElHuD0Pk7QSKb8DeRUemkB/KC1Ji DQ7nyCYUtwr5WFGs= X-Received: by 2002:a1c:b346:: with SMTP id c67mr24910wmf.105.1604414116057; Tue, 03 Nov 2020 06:35:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJyYi+0Ivik5e6d8j+dcxNAsqKhBCMOsodGyUD6lBdLMFX60z41PirvZePmee9W9rU5IvHygFA== X-Received: by 2002:a1c:b346:: with SMTP id c67mr24887wmf.105.1604414115727; Tue, 03 Nov 2020 06:35:15 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id t5sm3292891wmg.19.2020.11.03.06.35.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:35:15 -0800 (PST) Date: Tue, 3 Nov 2020 09:35:13 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 28/38] configure: introduce --enable-vhost-user-blk-server Message-ID: <20201103142306.71782-29-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-block@nongnu.org, Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Stefan Hajnoczi Make it possible to compile out the vhost-user-blk server. It is enabled by default on Linux. Note that vhost-user-server.c depends on libvhost-user, which requires CONFIG_LINUX. The CONFIG_VHOST_USER dependency was erroneous since that option controls vhost-user frontends (previously known as "master") and not device backends (previously known as "slave"). Signed-off-by: Stefan Hajnoczi Message-Id: <20201027173528.213464-3-stefanha@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- configure | 15 +++++++++++++++ block/export/export.c | 4 ++-- block/export/meson.build | 2 +- util/meson.build | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/configure b/configure index 2c3c69f118..b5e8f5f72c 100755 --- a/configure +++ b/configure @@ -329,6 +329,7 @@ vhost_crypto="" vhost_scsi="" vhost_vsock="" vhost_user="" +vhost_user_blk_server="" vhost_user_fs="" kvm="auto" hax="auto" @@ -1246,6 +1247,10 @@ for opt do ;; --enable-vhost-vsock) vhost_vsock="yes" ;; + --disable-vhost-user-blk-server) vhost_user_blk_server="no" + ;; + --enable-vhost-user-blk-server) vhost_user_blk_server="yes" + ;; --disable-vhost-user-fs) vhost_user_fs="no" ;; --enable-vhost-user-fs) vhost_user_fs="yes" @@ -1791,6 +1796,7 @@ disabled with --disable-FEATURE, default is enabled if available: vhost-crypto vhost-user-crypto backend support vhost-kernel vhost kernel backend support vhost-user vhost-user backend support + vhost-user-blk-server vhost-user-blk server support vhost-vdpa vhost-vdpa kernel backend support spice spice rbd rados block device (rbd) @@ -2382,6 +2388,12 @@ if test "$vhost_net" = ""; then test "$vhost_kernel" = "yes" && vhost_net=yes fi +# libvhost-user is Linux-only +test "$vhost_user_blk_server" = "" && vhost_user_blk_server=$linux +if test "$vhost_user_blk_server" = "yes" && test "$linux" = "no"; then + error_exit "--enable-vhost-user-blk-server is only available on Linux" +fi + ########################################## # pkg-config probe @@ -6275,6 +6287,9 @@ fi if test "$vhost_vdpa" = "yes" ; then echo "CONFIG_VHOST_VDPA=y" >> $config_host_mak fi +if test "$vhost_user_blk_server" = "yes" ; then + echo "CONFIG_VHOST_USER_BLK_SERVER=y" >> $config_host_mak +fi if test "$vhost_user_fs" = "yes" ; then echo "CONFIG_VHOST_USER_FS=y" >> $config_host_mak fi diff --git a/block/export/export.c b/block/export/export.c index c3478c6c97..bad6f21b1c 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -22,13 +22,13 @@ #include "qapi/qapi-commands-block-export.h" #include "qapi/qapi-events-block-export.h" #include "qemu/id.h" -#if defined(CONFIG_LINUX) && defined(CONFIG_VHOST_USER) +#ifdef CONFIG_VHOST_USER_BLK_SERVER #include "vhost-user-blk-server.h" #endif static const BlockExportDriver *blk_exp_drivers[] = { &blk_exp_nbd, -#if defined(CONFIG_LINUX) && defined(CONFIG_VHOST_USER) +#ifdef CONFIG_VHOST_USER_BLK_SERVER &blk_exp_vhost_user_blk, #endif }; diff --git a/block/export/meson.build b/block/export/meson.build index 9fb4fbf81d..19526435d8 100644 --- a/block/export/meson.build +++ b/block/export/meson.build @@ -1,2 +1,2 @@ blockdev_ss.add(files('export.c')) -blockdev_ss.add(when: ['CONFIG_LINUX', 'CONFIG_VHOST_USER'], if_true: files('vhost-user-blk-server.c')) +blockdev_ss.add(when: 'CONFIG_VHOST_USER_BLK_SERVER', if_true: files('vhost-user-blk-server.c')) diff --git a/util/meson.build b/util/meson.build index c5159ad79d..f359af0d46 100644 --- a/util/meson.build +++ b/util/meson.build @@ -66,7 +66,7 @@ if have_block util_ss.add(files('main-loop.c')) util_ss.add(files('nvdimm-utils.c')) util_ss.add(files('qemu-coroutine.c', 'qemu-coroutine-lock.c', 'qemu-coroutine-io.c')) - util_ss.add(when: ['CONFIG_LINUX', 'CONFIG_VHOST_USER'], if_true: [ + util_ss.add(when: 'CONFIG_LINUX', if_true: [ files('vhost-user-server.c'), vhost_user ]) util_ss.add(files('block-helpers.c')) From patchwork Tue Nov 3 14:35:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877831 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 5AE476A2 for ; Tue, 3 Nov 2020 14:51:40 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E5363223BF for ; Tue, 3 Nov 2020 14:51:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NmEfFPEK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E5363223BF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:37528 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxep-0000es-TL for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:51:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxPB-0005YU-5s for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:36114) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxP8-0006jz-W9 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414121; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=lgzOL39RvILiPn2GJxc4fQ6TNHjpeFII29h+nk2BQE8=; b=NmEfFPEKrNcFcbmVm06Vo34PiOa3stCvbdOI/pC2Jduiy66zA26LY65kbGBbG/76l/yHbT iPhl8bLtycTJ3w6ch6yGyicj//D5VwPCtmngJRHGMgOL3rhUyedL9O2020B6ct+9ZDwMHW TqHtkTr/JvCMUG0fCVjtTH7DC09eHqk= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-334-hJ0mudD8NlancbmhaN8qfw-1; Tue, 03 Nov 2020 09:35:20 -0500 X-MC-Unique: hJ0mudD8NlancbmhaN8qfw-1 Received: by mail-wr1-f71.google.com with SMTP id p12so383163wrx.3 for ; Tue, 03 Nov 2020 06:35:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=lgzOL39RvILiPn2GJxc4fQ6TNHjpeFII29h+nk2BQE8=; b=agCDazuoTMFKoiZbAdwl3p9D2psPJiAJMd6bMZF3EHoYi92EjFaQKyWZ2SGxTEiAUW powXXhdt/mJT6BsQ5JxdarSwMS3SKh6ujoHUxY8JkD3FDLvS6JNiyibU4Ooo+VJ5JVK0 9nEk2tgiQ4tyuZWKfx10CUCOb9E7ky8vcOlvRN714oi1eII6crEbMN3N+0R/tQ7I7ZvT rmGpa7Aprf20C1Xc1NZFlabJD1tbpeP3VvtNRoZO10k9ob0mYXH4dCRTriPACRZyeqO7 YineomqERqY3nRbXs1ptEhlOFsbvMQjlvfpIasWg35OePJxlOorrvr5lCrWAVfkBOPew oCJA== X-Gm-Message-State: AOAM5338zuUWL2MCG3yHBIbhgpJsKbeTUKq33c+WwtImfZKl8zLI4mEp DD9i7h4VGcWf75R7Dp3zYDzCdwiJrfFw0VuBMSaWYC4KZO2mz5tlJwFxzPYXzKQLsqlT5ubUl04 EyxAzNhh/YA+Fgpc= X-Received: by 2002:a5d:62c2:: with SMTP id o2mr13999643wrv.306.1604414118440; Tue, 03 Nov 2020 06:35:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJxNPlzMY8KNFSxytpWNzvNHoQRew0xzLMjgFtsxRU97nKzJFjwagAsFPiEl5/JWR/EIg54MAA== X-Received: by 2002:a5d:62c2:: with SMTP id o2mr13999623wrv.306.1604414118294; Tue, 03 Nov 2020 06:35:18 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id o10sm3126429wma.47.2020.11.03.06.35.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:35:17 -0800 (PST) Date: Tue, 3 Nov 2020 09:35:15 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 29/38] block/export: make vhost-user-blk config space little-endian Message-ID: <20201103142306.71782-30-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-block@nongnu.org, Coiby Xu , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Stefan Hajnoczi VIRTIO 1.0 devices have little-endian configuration space. The vhost-user-blk-server.c code already uses little-endian for virtqueue processing but not for the configuration space fields. Fix this so the vhost-user-blk export works on big-endian hosts. Signed-off-by: Stefan Hajnoczi Message-Id: <20201027173528.213464-4-stefanha@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- block/export/vhost-user-blk-server.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c index 41f4933d6e..33cc0818b8 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -264,7 +264,6 @@ static uint64_t vu_blk_get_protocol_features(VuDev *dev) static int vu_blk_get_config(VuDev *vu_dev, uint8_t *config, uint32_t len) { - /* TODO blkcfg must be little-endian for VIRTIO 1.0 */ VuServer *server = container_of(vu_dev, VuServer, vu_dev); VuBlkExport *vexp = container_of(server, VuBlkExport, vu_server); memcpy(config, &vexp->blkcfg, len); @@ -343,18 +342,18 @@ vu_blk_initialize_config(BlockDriverState *bs, uint32_t blk_size, uint16_t num_queues) { - config->capacity = bdrv_getlength(bs) >> BDRV_SECTOR_BITS; - config->blk_size = blk_size; - config->size_max = 0; - config->seg_max = 128 - 2; - config->min_io_size = 1; - config->opt_io_size = 1; - config->num_queues = num_queues; - config->max_discard_sectors = 32768; - config->max_discard_seg = 1; - config->discard_sector_alignment = config->blk_size >> 9; - config->max_write_zeroes_sectors = 32768; - config->max_write_zeroes_seg = 1; + config->capacity = cpu_to_le64(bdrv_getlength(bs) >> BDRV_SECTOR_BITS); + config->blk_size = cpu_to_le32(blk_size); + config->size_max = cpu_to_le32(0); + config->seg_max = cpu_to_le32(128 - 2); + config->min_io_size = cpu_to_le16(1); + config->opt_io_size = cpu_to_le32(1); + config->num_queues = cpu_to_le16(num_queues); + config->max_discard_sectors = cpu_to_le32(32768); + config->max_discard_seg = cpu_to_le32(1); + config->discard_sector_alignment = cpu_to_le32(config->blk_size >> 9); + config->max_write_zeroes_sectors = cpu_to_le32(32768); + config->max_write_zeroes_seg = cpu_to_le32(1); } static void vu_blk_exp_request_shutdown(BlockExport *exp) From patchwork Tue Nov 3 14:35:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877829 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 C363A92A for ; Tue, 3 Nov 2020 14:50:41 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 78EA422447 for ; Tue, 3 Nov 2020 14:50:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="jHhUyIss" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 78EA422447 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36198 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxdw-0008W4-GT for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:50:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxPC-0005bU-Vp for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25961) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxPB-0006m9-70 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414124; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=cS4KIfPlpUgVDDoFSeX7cKA8yzTJmgIIdFHv/xDSqc0=; b=jHhUyIssNNj8z5LFRrYbbm8S86Vp1Tsjm1xC8WT6AZ5oa5zXO/AR2tLa3/8XJOUXsj78s1 duxQkFLPH0eo38u+uap75kpjSo26HHsvozAmoPE6nmM7lcfyLapxrhhQYBZ23pxH3Xhgit NG0ttCbB2UUBCCjA/o+gPYo6lIrpj4o= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-247-rGXlJyh-P3m50WkvOEdBQg-1; Tue, 03 Nov 2020 09:35:22 -0500 X-MC-Unique: rGXlJyh-P3m50WkvOEdBQg-1 Received: by mail-wm1-f72.google.com with SMTP id t201so4681446wmt.1 for ; Tue, 03 Nov 2020 06:35:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=cS4KIfPlpUgVDDoFSeX7cKA8yzTJmgIIdFHv/xDSqc0=; b=mguJ8dKJeCq/RpjU7qcqpQ14HE8yx5ad2rnbxMBoU0vAtLIl8qboXyrtYUKD2fGF2G GA+TW71NJb0VjA7HMf7to7Tve676V1gaw1oTdhuB46p+SKVU0FaOcdLlu32g8qFtxkEc wPURHibKpUCwI9gX2MFC1VQnhzB40Z5JNphlEuHK877lwxJBt32PCjg2ECKfeEcvTdTe bq3+/jqdiT4WrqJm6hK6xeBVg/34uDZh2eRPakw5imE0XAarLejkPxy064rOSIlQartb AO1U2H/j0Zip3Gn+cBfBp3ksZ+5xUngggOvj9KfrPaW0zZddb1ulwVQrP0WOK2A5s27M kS7w== X-Gm-Message-State: AOAM530dqkdikh2/Ext+AP38qnw1nMLetrH7oLRTul25Ckuz/kLeg2dP 6p3HeAcmMoekTUv29BiXOikTa/eBLWHpHAk5S3ZLwNxryFX5IQmqtPL9LBWzeTaf2KEggCEDyJV 9QZ1u/7dzz7CH0XA= X-Received: by 2002:adf:fa4e:: with SMTP id y14mr25906251wrr.377.1604414120999; Tue, 03 Nov 2020 06:35:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJzIrmSW2G5zmuho0M5p+QIiHcE6jvrzbxdVfp4pWr0wX4snTWgG781v0ar2o6fQlVdtR0RB/w== X-Received: by 2002:adf:fa4e:: with SMTP id y14mr25906232wrr.377.1604414120851; Tue, 03 Nov 2020 06:35:20 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id d134sm2974281wmd.8.2020.11.03.06.35.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:35:20 -0800 (PST) Date: Tue, 3 Nov 2020 09:35:18 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 30/38] block/export: fix vhost-user-blk get_config() information leak Message-ID: <20201103142306.71782-31-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-block@nongnu.org, Coiby Xu , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Stefan Hajnoczi Refuse get_config() requests in excess of sizeof(struct virtio_blk_config). Signed-off-by: Stefan Hajnoczi Message-Id: <20201027173528.213464-5-stefanha@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- block/export/vhost-user-blk-server.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c index 33cc0818b8..62672d1cb9 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -266,6 +266,9 @@ vu_blk_get_config(VuDev *vu_dev, uint8_t *config, uint32_t len) { VuServer *server = container_of(vu_dev, VuServer, vu_dev); VuBlkExport *vexp = container_of(server, VuBlkExport, vu_server); + + g_return_val_if_fail(len <= sizeof(struct virtio_blk_config), -1); + memcpy(config, &vexp->blkcfg, len); return 0; } From patchwork Tue Nov 3 14:35:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877835 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 D24FA6A2 for ; Tue, 3 Nov 2020 14:52:53 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6B6602076E for ; Tue, 3 Nov 2020 14:52:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="X0b/Tzg+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6B6602076E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:41538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxg1-0002K8-MK for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:52:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxPJ-0005fP-KD for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:55685) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxPF-0006nR-Kt for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414127; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=10gqAcInC2hOlA/e3e/PPVyOBwthTxnTi3QFwwaBdNU=; b=X0b/Tzg+02Nafd4zXgJzj9Va/Ys7cQxK4VvI+Xfj84yBmtmAEAUiQRse1636T3tjDB9lWl EqCYxjaDdACLzqLuh+O8fjlVoYoau99C7LqbvW0PP6cjy4KgmIMvPHmBPFJlVtDS9ZONy1 b52vVv4+3KzZyobLZ7dp/RKUFbzxeiA= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-596-FH-La_UyOP2-qmryxl0oZg-1; Tue, 03 Nov 2020 09:35:25 -0500 X-MC-Unique: FH-La_UyOP2-qmryxl0oZg-1 Received: by mail-wm1-f72.google.com with SMTP id b68so2700438wme.5 for ; Tue, 03 Nov 2020 06:35:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=10gqAcInC2hOlA/e3e/PPVyOBwthTxnTi3QFwwaBdNU=; b=nkLSlz5UXFAuwUFApSFDj9IiBmTcfGW5y2/iNeEZsahLRCyq6yuOahimcmkFzaJ/MY hO8IZR939XgLXbrW2neyaRQ2oAnqXEJ8QSfxuXnoPl3pUKa7u/SYw0JmngvCmqkrJFuL Mab2ltpVlL7SBn0TG10mmCzRJf4UNmnSbH9ThECGOZss7F+EeUqJ6U3BilC6bLirKtHR dQIB9JxvF4dtLAHelDzLTAfObYXAOV/bhFIbwKy4evMZI+CLiW5lYT+HG/Ikk4G2t7zg XygvliZiU55cClDfnxlh0OwgL2yclCtDteKQ6GwJVAVdu5Vl89zy8wrZguLUlCHnPqSl bm7g== X-Gm-Message-State: AOAM533izhOhmSIuQEWRhNuxlkTdD2N+oi+I9L61cxMgx/C/cc9v5BNT 4IiRnHvx+sBY+LAIgH2yOvntdpdLp9oHtvkrhAz6h2rtBmvU5euQtOqQBP5UCjsATRYNW7hxKE4 SUl4SkSOnXx0drfE= X-Received: by 2002:a5d:4ed2:: with SMTP id s18mr26377955wrv.36.1604414123320; Tue, 03 Nov 2020 06:35:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJzaXjHdulBeP172CMP0msW9+vhadYdpX/wA5kqGEhum/CFy7DPYq6bQUUmOPzpIBvKpL1jlSQ== X-Received: by 2002:a5d:4ed2:: with SMTP id s18mr26377935wrv.36.1604414123177; Tue, 03 Nov 2020 06:35:23 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id t23sm3037003wmn.13.2020.11.03.06.35.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:35:22 -0800 (PST) Date: Tue, 3 Nov 2020 09:35:21 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 31/38] contrib/vhost-user-blk: fix get_config() information leak Message-ID: <20201103142306.71782-32-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stefan Hajnoczi , Raphael Norwitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Stefan Hajnoczi Refuse get_config() in excess of sizeof(struct virtio_blk_config). Signed-off-by: Stefan Hajnoczi Message-Id: <20201027173528.213464-6-stefanha@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- contrib/vhost-user-blk/vhost-user-blk.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-blk/vhost-user-blk.c index 25eccd02b5..caad88637e 100644 --- a/contrib/vhost-user-blk/vhost-user-blk.c +++ b/contrib/vhost-user-blk/vhost-user-blk.c @@ -404,6 +404,8 @@ vub_get_config(VuDev *vu_dev, uint8_t *config, uint32_t len) VugDev *gdev; VubDev *vdev_blk; + g_return_val_if_fail(len <= sizeof(struct virtio_blk_config), -1); + gdev = container_of(vu_dev, VugDev, parent); vdev_blk = container_of(gdev, VubDev, parent); memcpy(config, &vdev_blk->blkcfg, len); From patchwork Tue Nov 3 14:35:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877869 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 A4DA96A2 for ; Tue, 3 Nov 2020 14:56:06 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2726D20757 for ; Tue, 3 Nov 2020 14:56:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hzW1lyjR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2726D20757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:53162 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxj4-0007If-T5 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:56:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxPa-0005lF-Kq for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:25267) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxPO-0006sp-V0 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414136; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vmZ6U03tiWRzo3OOmOXOEZgB2Q0tAfyx5o0TEqeDgWk=; b=hzW1lyjRngrVGFTHzTh0pldswuD1kg+tTN9duYYz44fPGGnDsfRGuTihG3KJHju4jwsjjk Y5FdKSaa07qKGhJ7CvEqkFBdsv2UUZdbhRKhNmmHo/QPMFMqbbBZmUFAgSS89XnVfhdv5a ExNXwBIP0cKEsn5LNLVrSLeZ8VcMquQ= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-42-5Ejvox_UMYK_-38B2dnUZg-1; Tue, 03 Nov 2020 09:35:31 -0500 X-MC-Unique: 5Ejvox_UMYK_-38B2dnUZg-1 Received: by mail-wm1-f72.google.com with SMTP id s85so2704863wme.3 for ; Tue, 03 Nov 2020 06:35:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=vmZ6U03tiWRzo3OOmOXOEZgB2Q0tAfyx5o0TEqeDgWk=; b=Gek8ASf9QvgSLcJTsn6eomUORxhKrwfbtXpVkSEQ2TIyZtuCrzkdhOJ3MHZ9kVp6Nf UMLB0I1CQzvzBjoqfZpV1hLSMdEH70xLPpynA08ss+nohR0fR5+ectDmba0pmySRpham IrqNFfrOWjTXAm/bKCsGXkc0esYhMAjiyGBoIHg/Jqn8jb8eBPInAxbW0huKeDp48nPH CucqW7EX3YIopYgNj6r79umnYd9wkOw03/XFlqgX+bz3DlO/DrM4a8P3LZwJqCQXN0AL 8J8bwuCSCPO0PJLgh6gff/FDM6FuKOfmsornAj7xiBx7DO0/jtMFuq5WWtW22ezanrDa AAMg== X-Gm-Message-State: AOAM530lsCAkwHW6IoEP5KENf/MqxmGkYJL9Cmso7vYhMNwbxPML2ReW 9Qs7uyeZKudtjEuLG0wzCJzi8EvAY/nuAZGwFAHJOAeBbAxc2Br4WkOauVApHNAsc6RQ1Av2c04 o91nYc8tJlzbKLbo= X-Received: by 2002:a1c:23cf:: with SMTP id j198mr92355wmj.6.1604414126511; Tue, 03 Nov 2020 06:35:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJzLK0+AfIQKMr5Fq8iHDO8oJfOfajvnsJr0s5vIruSdQUWUAv1CtBC1fSLA6Qzwsmly/IN/Zw== X-Received: by 2002:a1c:23cf:: with SMTP id j198mr92306wmj.6.1604414126019; Tue, 03 Nov 2020 06:35:26 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id t4sm3121224wmb.20.2020.11.03.06.35.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:35:25 -0800 (PST) Date: Tue, 3 Nov 2020 09:35:23 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 32/38] test: new qTest case to test the vhost-user-blk-server Message-ID: <20201103142306.71782-33-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Peter Maydell , Thomas Huth , Coiby Xu , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9?= Lureau Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Coiby Xu This test case has the same tests as tests/virtio-blk-test.c except for tests have block_resize. Since vhost-user server can only server one client one time, two instances of vhost-user-blk-server are started by qemu-storage-daemon for the hotplug test. In order to not block scripts/tap-driver.pl, vhost-user-blk-server will send "quit" command to qemu-storage-daemon's QMP monitor. So a function is added to libqtest.c to establish socket connection with socket server. Suggested-by: Thomas Huth Signed-off-by: Coiby Xu Reviewed-by: Stefan Hajnoczi Reviewed-by: Marc-André Lureau Message-id: 20200918080912.321299-7-coiby.xu@gmail.com [Update meson.build to only test when CONFIG_TOOLS has built qemu-storage-daemon. This prevents CI failures with --disable-tools. Also bump RAM to 256 MB because that is the minimum RAM granularity on ppc64 spapr machines. --Stefan] Signed-off-by: Stefan Hajnoczi Message-Id: <20201027173528.213464-7-stefanha@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/qtest/libqos/libqtest.h | 17 + tests/qtest/libqos/vhost-user-blk.h | 48 ++ tests/qtest/libqos/vhost-user-blk.c | 129 +++++ tests/qtest/libqtest.c | 36 +- tests/qtest/vhost-user-blk-test.c | 751 ++++++++++++++++++++++++++++ tests/qtest/libqos/meson.build | 1 + tests/qtest/meson.build | 2 + 7 files changed, 982 insertions(+), 2 deletions(-) create mode 100644 tests/qtest/libqos/vhost-user-blk.h create mode 100644 tests/qtest/libqos/vhost-user-blk.c create mode 100644 tests/qtest/vhost-user-blk-test.c diff --git a/tests/qtest/libqos/libqtest.h b/tests/qtest/libqos/libqtest.h index 5c959f1853..241b5f89fb 100644 --- a/tests/qtest/libqos/libqtest.h +++ b/tests/qtest/libqos/libqtest.h @@ -132,6 +132,23 @@ void qtest_qmp_send(QTestState *s, const char *fmt, ...) void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...) GCC_FMT_ATTR(2, 3); +/** + * qtest_socket_client: + * @server_socket_path: the socket server's path + * + * Connect to a socket server. + */ +int qtest_socket_client(char *server_socket_path); + +/** + * qtest_create_state_with_qmp_fd: + * @fd: socket fd + * + * Wrap socket fd in QTestState to make use of qtest_qmp* + * functions + */ +QTestState *qtest_create_state_with_qmp_fd(int fd); + /** * qtest_vqmp_fds: * @s: #QTestState instance to operate on. diff --git a/tests/qtest/libqos/vhost-user-blk.h b/tests/qtest/libqos/vhost-user-blk.h new file mode 100644 index 0000000000..2a03456a45 --- /dev/null +++ b/tests/qtest/libqos/vhost-user-blk.h @@ -0,0 +1,48 @@ +/* + * libqos driver framework + * + * Based on tests/qtest/libqos/virtio-blk.c + * + * Copyright (c) 2020 Coiby Xu + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#ifndef TESTS_LIBQOS_VHOST_USER_BLK_H +#define TESTS_LIBQOS_VHOST_USER_BLK_H + +#include "qgraph.h" +#include "virtio.h" +#include "virtio-pci.h" + +typedef struct QVhostUserBlk QVhostUserBlk; +typedef struct QVhostUserBlkPCI QVhostUserBlkPCI; +typedef struct QVhostUserBlkDevice QVhostUserBlkDevice; + +struct QVhostUserBlk { + QVirtioDevice *vdev; +}; + +struct QVhostUserBlkPCI { + QVirtioPCIDevice pci_vdev; + QVhostUserBlk blk; +}; + +struct QVhostUserBlkDevice { + QOSGraphObject obj; + QVhostUserBlk blk; +}; + +#endif diff --git a/tests/qtest/libqos/vhost-user-blk.c b/tests/qtest/libqos/vhost-user-blk.c new file mode 100644 index 0000000000..58c7e1eb69 --- /dev/null +++ b/tests/qtest/libqos/vhost-user-blk.c @@ -0,0 +1,129 @@ +/* + * libqos driver framework + * + * Based on tests/qtest/libqos/virtio-blk.c + * + * Copyright (c) 2020 Coiby Xu + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "qemu/module.h" +#include "standard-headers/linux/virtio_blk.h" +#include "vhost-user-blk.h" + +#define PCI_SLOT 0x04 +#define PCI_FN 0x00 + +/* virtio-blk-device */ +static void *qvhost_user_blk_get_driver(QVhostUserBlk *v_blk, + const char *interface) +{ + if (!g_strcmp0(interface, "vhost-user-blk")) { + return v_blk; + } + if (!g_strcmp0(interface, "virtio")) { + return v_blk->vdev; + } + + fprintf(stderr, "%s not present in vhost-user-blk-device\n", interface); + g_assert_not_reached(); +} + +static void *qvhost_user_blk_device_get_driver(void *object, + const char *interface) +{ + QVhostUserBlkDevice *v_blk = object; + return qvhost_user_blk_get_driver(&v_blk->blk, interface); +} + +static void *vhost_user_blk_device_create(void *virtio_dev, + QGuestAllocator *t_alloc, + void *addr) +{ + QVhostUserBlkDevice *vhost_user_blk = g_new0(QVhostUserBlkDevice, 1); + QVhostUserBlk *interface = &vhost_user_blk->blk; + + interface->vdev = virtio_dev; + + vhost_user_blk->obj.get_driver = qvhost_user_blk_device_get_driver; + + return &vhost_user_blk->obj; +} + +/* virtio-blk-pci */ +static void *qvhost_user_blk_pci_get_driver(void *object, const char *interface) +{ + QVhostUserBlkPCI *v_blk = object; + if (!g_strcmp0(interface, "pci-device")) { + return v_blk->pci_vdev.pdev; + } + return qvhost_user_blk_get_driver(&v_blk->blk, interface); +} + +static void *vhost_user_blk_pci_create(void *pci_bus, QGuestAllocator *t_alloc, + void *addr) +{ + QVhostUserBlkPCI *vhost_user_blk = g_new0(QVhostUserBlkPCI, 1); + QVhostUserBlk *interface = &vhost_user_blk->blk; + QOSGraphObject *obj = &vhost_user_blk->pci_vdev.obj; + + virtio_pci_init(&vhost_user_blk->pci_vdev, pci_bus, addr); + interface->vdev = &vhost_user_blk->pci_vdev.vdev; + + g_assert_cmphex(interface->vdev->device_type, ==, VIRTIO_ID_BLOCK); + + obj->get_driver = qvhost_user_blk_pci_get_driver; + + return obj; +} + +static void vhost_user_blk_register_nodes(void) +{ + /* + * FIXME: every test using these two nodes needs to setup a + * -drive,id=drive0 otherwise QEMU is not going to start. + * Therefore, we do not include "produces" edge for virtio + * and pci-device yet. + */ + + char *arg = g_strdup_printf("id=drv0,chardev=char1,addr=%x.%x", + PCI_SLOT, PCI_FN); + + QPCIAddress addr = { + .devfn = QPCI_DEVFN(PCI_SLOT, PCI_FN), + }; + + QOSGraphEdgeOptions opts = { }; + + /* virtio-blk-device */ + /** opts.extra_device_opts = "drive=drive0"; */ + qos_node_create_driver("vhost-user-blk-device", vhost_user_blk_device_create); + qos_node_consumes("vhost-user-blk-device", "virtio-bus", &opts); + qos_node_produces("vhost-user-blk-device", "vhost-user-blk"); + + /* virtio-blk-pci */ + opts.extra_device_opts = arg; + add_qpci_address(&opts, &addr); + qos_node_create_driver("vhost-user-blk-pci", vhost_user_blk_pci_create); + qos_node_consumes("vhost-user-blk-pci", "pci-bus", &opts); + qos_node_produces("vhost-user-blk-pci", "vhost-user-blk"); + + g_free(arg); +} + +libqos_init(vhost_user_blk_register_nodes); diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 99deff47ef..ab34075f2b 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -4,11 +4,13 @@ * Copyright IBM, Corp. 2012 * Copyright Red Hat, Inc. 2012 * Copyright SUSE LINUX Products GmbH 2013 + * Copyright Copyright (c) Coiby Xu * * Authors: * Anthony Liguori * Paolo Bonzini * Andreas Färber + * Coiby Xu * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. @@ -52,8 +54,7 @@ typedef struct QTestClientTransportOps { QTestRecvFn recv_line; /* for receiving qtest command responses */ } QTestTransportOps; -struct QTestState -{ +struct QTestState { int fd; int qmp_fd; pid_t qemu_pid; /* our child QEMU process */ @@ -630,6 +631,37 @@ QDict *qtest_qmp_receive_dict(QTestState *s) return qmp_fd_receive(s->qmp_fd); } +QTestState *qtest_create_state_with_qmp_fd(int fd) +{ + QTestState *qmp_test_state = g_new0(QTestState, 1); + qmp_test_state->qmp_fd = fd; + return qmp_test_state; +} + +int qtest_socket_client(char *server_socket_path) +{ + struct sockaddr_un serv_addr; + int sock; + int ret; + int retries = 0; + sock = socket(PF_UNIX, SOCK_STREAM, 0); + g_assert_cmpint(sock, !=, -1); + serv_addr.sun_family = AF_UNIX; + snprintf(serv_addr.sun_path, sizeof(serv_addr.sun_path), "%s", + server_socket_path); + + for (retries = 0; retries < 3; retries++) { + ret = connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)); + if (ret == 0) { + break; + } + g_usleep(G_USEC_PER_SEC); + } + + g_assert_cmpint(ret, ==, 0); + return sock; +} + /** * Allow users to send a message without waiting for the reply, * in the case that they choose to discard all replies up until diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk-test.c new file mode 100644 index 0000000000..e7e44f9bf0 --- /dev/null +++ b/tests/qtest/vhost-user-blk-test.c @@ -0,0 +1,751 @@ +/* + * QTest testcase for Vhost-user Block Device + * + * Based on tests/qtest//virtio-blk-test.c + + * Copyright (c) 2014 SUSE LINUX Products GmbH + * Copyright (c) 2014 Marc Marí + * Copyright (c) 2020 Coiby Xu + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "libqtest-single.h" +#include "qemu/bswap.h" +#include "qemu/module.h" +#include "standard-headers/linux/virtio_blk.h" +#include "standard-headers/linux/virtio_pci.h" +#include "libqos/qgraph.h" +#include "libqos/vhost-user-blk.h" +#include "libqos/libqos-pc.h" + +#define TEST_IMAGE_SIZE (64 * 1024 * 1024) +#define QVIRTIO_BLK_TIMEOUT_US (30 * 1000 * 1000) +#define PCI_SLOT_HP 0x06 + +typedef struct QVirtioBlkReq { + uint32_t type; + uint32_t ioprio; + uint64_t sector; + char *data; + uint8_t status; +} QVirtioBlkReq; + +#ifdef HOST_WORDS_BIGENDIAN +static const bool host_is_big_endian = true; +#else +static const bool host_is_big_endian; /* false */ +#endif + +static inline void virtio_blk_fix_request(QVirtioDevice *d, QVirtioBlkReq *req) +{ + if (qvirtio_is_big_endian(d) != host_is_big_endian) { + req->type = bswap32(req->type); + req->ioprio = bswap32(req->ioprio); + req->sector = bswap64(req->sector); + } +} + +static inline void virtio_blk_fix_dwz_hdr(QVirtioDevice *d, + struct virtio_blk_discard_write_zeroes *dwz_hdr) +{ + if (qvirtio_is_big_endian(d) != host_is_big_endian) { + dwz_hdr->sector = bswap64(dwz_hdr->sector); + dwz_hdr->num_sectors = bswap32(dwz_hdr->num_sectors); + dwz_hdr->flags = bswap32(dwz_hdr->flags); + } +} + +static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioDevice *d, + QVirtioBlkReq *req, uint64_t data_size) +{ + uint64_t addr; + uint8_t status = 0xFF; + QTestState *qts = global_qtest; + + switch (req->type) { + case VIRTIO_BLK_T_IN: + case VIRTIO_BLK_T_OUT: + g_assert_cmpuint(data_size % 512, ==, 0); + break; + case VIRTIO_BLK_T_DISCARD: + case VIRTIO_BLK_T_WRITE_ZEROES: + g_assert_cmpuint(data_size % + sizeof(struct virtio_blk_discard_write_zeroes), ==, 0); + break; + default: + g_assert_cmpuint(data_size, ==, 0); + } + + addr = guest_alloc(alloc, sizeof(*req) + data_size); + + virtio_blk_fix_request(d, req); + + qtest_memwrite(qts, addr, req, 16); + qtest_memwrite(qts, addr + 16, req->data, data_size); + qtest_memwrite(qts, addr + 16 + data_size, &status, sizeof(status)); + + return addr; +} + +/* Returns the request virtqueue so the caller can perform further tests */ +static QVirtQueue *test_basic(QVirtioDevice *dev, QGuestAllocator *alloc) +{ + QVirtioBlkReq req; + uint64_t req_addr; + uint64_t capacity; + uint64_t features; + uint32_t free_head; + uint8_t status; + char *data; + QTestState *qts = global_qtest; + QVirtQueue *vq; + + features = qvirtio_get_features(dev); + features = features & ~(QVIRTIO_F_BAD_FEATURE | + (1u << VIRTIO_RING_F_INDIRECT_DESC) | + (1u << VIRTIO_RING_F_EVENT_IDX) | + (1u << VIRTIO_BLK_F_SCSI)); + qvirtio_set_features(dev, features); + + capacity = qvirtio_config_readq(dev, 0); + g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); + + vq = qvirtqueue_setup(dev, alloc, 0); + + qvirtio_set_driver_ok(dev); + + /* Write and read with 3 descriptor layout */ + /* Write request */ + req.type = VIRTIO_BLK_T_OUT; + req.ioprio = 1; + req.sector = 0; + req.data = g_malloc0(512); + strcpy(req.data, "TEST"); + + req_addr = virtio_blk_request(alloc, dev, &req, 512); + + g_free(req.data); + + free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true); + qvirtqueue_add(qts, vq, req_addr + 16, 512, false, true); + qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false); + + qvirtqueue_kick(qts, dev, vq, free_head); + + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, + QVIRTIO_BLK_TIMEOUT_US); + status = readb(req_addr + 528); + g_assert_cmpint(status, ==, 0); + + guest_free(alloc, req_addr); + + /* Read request */ + req.type = VIRTIO_BLK_T_IN; + req.ioprio = 1; + req.sector = 0; + req.data = g_malloc0(512); + + req_addr = virtio_blk_request(alloc, dev, &req, 512); + + g_free(req.data); + + free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true); + qvirtqueue_add(qts, vq, req_addr + 16, 512, true, true); + qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false); + + qvirtqueue_kick(qts, dev, vq, free_head); + + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, + QVIRTIO_BLK_TIMEOUT_US); + status = readb(req_addr + 528); + g_assert_cmpint(status, ==, 0); + + data = g_malloc0(512); + qtest_memread(qts, req_addr + 16, data, 512); + g_assert_cmpstr(data, ==, "TEST"); + g_free(data); + + guest_free(alloc, req_addr); + + if (features & (1u << VIRTIO_BLK_F_WRITE_ZEROES)) { + struct virtio_blk_discard_write_zeroes dwz_hdr; + void *expected; + + /* + * WRITE_ZEROES request on the same sector of previous test where + * we wrote "TEST". + */ + req.type = VIRTIO_BLK_T_WRITE_ZEROES; + req.data = (char *) &dwz_hdr; + dwz_hdr.sector = 0; + dwz_hdr.num_sectors = 1; + dwz_hdr.flags = 0; + + virtio_blk_fix_dwz_hdr(dev, &dwz_hdr); + + req_addr = virtio_blk_request(alloc, dev, &req, sizeof(dwz_hdr)); + + free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true); + qvirtqueue_add(qts, vq, req_addr + 16, sizeof(dwz_hdr), false, true); + qvirtqueue_add(qts, vq, req_addr + 16 + sizeof(dwz_hdr), 1, true, + false); + + qvirtqueue_kick(qts, dev, vq, free_head); + + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, + QVIRTIO_BLK_TIMEOUT_US); + status = readb(req_addr + 16 + sizeof(dwz_hdr)); + g_assert_cmpint(status, ==, 0); + + guest_free(alloc, req_addr); + + /* Read request to check if the sector contains all zeroes */ + req.type = VIRTIO_BLK_T_IN; + req.ioprio = 1; + req.sector = 0; + req.data = g_malloc0(512); + + req_addr = virtio_blk_request(alloc, dev, &req, 512); + + g_free(req.data); + + free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true); + qvirtqueue_add(qts, vq, req_addr + 16, 512, true, true); + qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false); + + qvirtqueue_kick(qts, dev, vq, free_head); + + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, + QVIRTIO_BLK_TIMEOUT_US); + status = readb(req_addr + 528); + g_assert_cmpint(status, ==, 0); + + data = g_malloc(512); + expected = g_malloc0(512); + qtest_memread(qts, req_addr + 16, data, 512); + g_assert_cmpmem(data, 512, expected, 512); + g_free(expected); + g_free(data); + + guest_free(alloc, req_addr); + } + + if (features & (1u << VIRTIO_BLK_F_DISCARD)) { + struct virtio_blk_discard_write_zeroes dwz_hdr; + + req.type = VIRTIO_BLK_T_DISCARD; + req.data = (char *) &dwz_hdr; + dwz_hdr.sector = 0; + dwz_hdr.num_sectors = 1; + dwz_hdr.flags = 0; + + virtio_blk_fix_dwz_hdr(dev, &dwz_hdr); + + req_addr = virtio_blk_request(alloc, dev, &req, sizeof(dwz_hdr)); + + free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true); + qvirtqueue_add(qts, vq, req_addr + 16, sizeof(dwz_hdr), false, true); + qvirtqueue_add(qts, vq, req_addr + 16 + sizeof(dwz_hdr), + 1, true, false); + + qvirtqueue_kick(qts, dev, vq, free_head); + + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, + QVIRTIO_BLK_TIMEOUT_US); + status = readb(req_addr + 16 + sizeof(dwz_hdr)); + g_assert_cmpint(status, ==, 0); + + guest_free(alloc, req_addr); + } + + if (features & (1u << VIRTIO_F_ANY_LAYOUT)) { + /* Write and read with 2 descriptor layout */ + /* Write request */ + req.type = VIRTIO_BLK_T_OUT; + req.ioprio = 1; + req.sector = 1; + req.data = g_malloc0(512); + strcpy(req.data, "TEST"); + + req_addr = virtio_blk_request(alloc, dev, &req, 512); + + g_free(req.data); + + free_head = qvirtqueue_add(qts, vq, req_addr, 528, false, true); + qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false); + qvirtqueue_kick(qts, dev, vq, free_head); + + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, + QVIRTIO_BLK_TIMEOUT_US); + status = readb(req_addr + 528); + g_assert_cmpint(status, ==, 0); + + guest_free(alloc, req_addr); + + /* Read request */ + req.type = VIRTIO_BLK_T_IN; + req.ioprio = 1; + req.sector = 1; + req.data = g_malloc0(512); + + req_addr = virtio_blk_request(alloc, dev, &req, 512); + + g_free(req.data); + + free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true); + qvirtqueue_add(qts, vq, req_addr + 16, 513, true, false); + + qvirtqueue_kick(qts, dev, vq, free_head); + + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, + QVIRTIO_BLK_TIMEOUT_US); + status = readb(req_addr + 528); + g_assert_cmpint(status, ==, 0); + + data = g_malloc0(512); + qtest_memread(qts, req_addr + 16, data, 512); + g_assert_cmpstr(data, ==, "TEST"); + g_free(data); + + guest_free(alloc, req_addr); + } + + return vq; +} + +static void basic(void *obj, void *data, QGuestAllocator *t_alloc) +{ + QVhostUserBlk *blk_if = obj; + QVirtQueue *vq; + + vq = test_basic(blk_if->vdev, t_alloc); + qvirtqueue_cleanup(blk_if->vdev->bus, vq, t_alloc); + +} + +static void indirect(void *obj, void *u_data, QGuestAllocator *t_alloc) +{ + QVirtQueue *vq; + QVhostUserBlk *blk_if = obj; + QVirtioDevice *dev = blk_if->vdev; + QVirtioBlkReq req; + QVRingIndirectDesc *indirect; + uint64_t req_addr; + uint64_t capacity; + uint64_t features; + uint32_t free_head; + uint8_t status; + char *data; + QTestState *qts = global_qtest; + + features = qvirtio_get_features(dev); + g_assert_cmphex(features & (1u << VIRTIO_RING_F_INDIRECT_DESC), !=, 0); + features = features & ~(QVIRTIO_F_BAD_FEATURE | + (1u << VIRTIO_RING_F_EVENT_IDX) | + (1u << VIRTIO_BLK_F_SCSI)); + qvirtio_set_features(dev, features); + + capacity = qvirtio_config_readq(dev, 0); + g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); + + vq = qvirtqueue_setup(dev, t_alloc, 0); + qvirtio_set_driver_ok(dev); + + /* Write request */ + req.type = VIRTIO_BLK_T_OUT; + req.ioprio = 1; + req.sector = 0; + req.data = g_malloc0(512); + strcpy(req.data, "TEST"); + + req_addr = virtio_blk_request(t_alloc, dev, &req, 512); + + g_free(req.data); + + indirect = qvring_indirect_desc_setup(qts, dev, t_alloc, 2); + qvring_indirect_desc_add(dev, qts, indirect, req_addr, 528, false); + qvring_indirect_desc_add(dev, qts, indirect, req_addr + 528, 1, true); + free_head = qvirtqueue_add_indirect(qts, vq, indirect); + qvirtqueue_kick(qts, dev, vq, free_head); + + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, + QVIRTIO_BLK_TIMEOUT_US); + status = readb(req_addr + 528); + g_assert_cmpint(status, ==, 0); + + g_free(indirect); + guest_free(t_alloc, req_addr); + + /* Read request */ + req.type = VIRTIO_BLK_T_IN; + req.ioprio = 1; + req.sector = 0; + req.data = g_malloc0(512); + strcpy(req.data, "TEST"); + + req_addr = virtio_blk_request(t_alloc, dev, &req, 512); + + g_free(req.data); + + indirect = qvring_indirect_desc_setup(qts, dev, t_alloc, 2); + qvring_indirect_desc_add(dev, qts, indirect, req_addr, 16, false); + qvring_indirect_desc_add(dev, qts, indirect, req_addr + 16, 513, true); + free_head = qvirtqueue_add_indirect(qts, vq, indirect); + qvirtqueue_kick(qts, dev, vq, free_head); + + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, + QVIRTIO_BLK_TIMEOUT_US); + status = readb(req_addr + 528); + g_assert_cmpint(status, ==, 0); + + data = g_malloc0(512); + qtest_memread(qts, req_addr + 16, data, 512); + g_assert_cmpstr(data, ==, "TEST"); + g_free(data); + + g_free(indirect); + guest_free(t_alloc, req_addr); + qvirtqueue_cleanup(dev->bus, vq, t_alloc); +} + +static void idx(void *obj, void *u_data, QGuestAllocator *t_alloc) +{ + QVirtQueue *vq; + QVhostUserBlkPCI *blk = obj; + QVirtioPCIDevice *pdev = &blk->pci_vdev; + QVirtioDevice *dev = &pdev->vdev; + QVirtioBlkReq req; + uint64_t req_addr; + uint64_t capacity; + uint64_t features; + uint32_t free_head; + uint32_t write_head; + uint32_t desc_idx; + uint8_t status; + char *data; + QOSGraphObject *blk_object = obj; + QPCIDevice *pci_dev = blk_object->get_driver(blk_object, "pci-device"); + QTestState *qts = global_qtest; + + if (qpci_check_buggy_msi(pci_dev)) { + return; + } + + qpci_msix_enable(pdev->pdev); + qvirtio_pci_set_msix_configuration_vector(pdev, t_alloc, 0); + + features = qvirtio_get_features(dev); + features = features & ~(QVIRTIO_F_BAD_FEATURE | + (1u << VIRTIO_RING_F_INDIRECT_DESC) | + (1u << VIRTIO_F_NOTIFY_ON_EMPTY) | + (1u << VIRTIO_BLK_F_SCSI)); + qvirtio_set_features(dev, features); + + capacity = qvirtio_config_readq(dev, 0); + g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); + + vq = qvirtqueue_setup(dev, t_alloc, 0); + qvirtqueue_pci_msix_setup(pdev, (QVirtQueuePCI *)vq, t_alloc, 1); + + qvirtio_set_driver_ok(dev); + + /* Write request */ + req.type = VIRTIO_BLK_T_OUT; + req.ioprio = 1; + req.sector = 0; + req.data = g_malloc0(512); + strcpy(req.data, "TEST"); + + req_addr = virtio_blk_request(t_alloc, dev, &req, 512); + + g_free(req.data); + + free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true); + qvirtqueue_add(qts, vq, req_addr + 16, 512, false, true); + qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false); + qvirtqueue_kick(qts, dev, vq, free_head); + + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, + QVIRTIO_BLK_TIMEOUT_US); + + /* Write request */ + req.type = VIRTIO_BLK_T_OUT; + req.ioprio = 1; + req.sector = 1; + req.data = g_malloc0(512); + strcpy(req.data, "TEST"); + + req_addr = virtio_blk_request(t_alloc, dev, &req, 512); + + g_free(req.data); + + /* Notify after processing the third request */ + qvirtqueue_set_used_event(qts, vq, 2); + free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true); + qvirtqueue_add(qts, vq, req_addr + 16, 512, false, true); + qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false); + qvirtqueue_kick(qts, dev, vq, free_head); + write_head = free_head; + + /* No notification expected */ + status = qvirtio_wait_status_byte_no_isr(qts, dev, + vq, req_addr + 528, + QVIRTIO_BLK_TIMEOUT_US); + g_assert_cmpint(status, ==, 0); + + guest_free(t_alloc, req_addr); + + /* Read request */ + req.type = VIRTIO_BLK_T_IN; + req.ioprio = 1; + req.sector = 1; + req.data = g_malloc0(512); + + req_addr = virtio_blk_request(t_alloc, dev, &req, 512); + + g_free(req.data); + + free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true); + qvirtqueue_add(qts, vq, req_addr + 16, 512, true, true); + qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false); + + qvirtqueue_kick(qts, dev, vq, free_head); + + /* We get just one notification for both requests */ + qvirtio_wait_used_elem(qts, dev, vq, write_head, NULL, + QVIRTIO_BLK_TIMEOUT_US); + g_assert(qvirtqueue_get_buf(qts, vq, &desc_idx, NULL)); + g_assert_cmpint(desc_idx, ==, free_head); + + status = readb(req_addr + 528); + g_assert_cmpint(status, ==, 0); + + data = g_malloc0(512); + qtest_memread(qts, req_addr + 16, data, 512); + g_assert_cmpstr(data, ==, "TEST"); + g_free(data); + + guest_free(t_alloc, req_addr); + + /* End test */ + qpci_msix_disable(pdev->pdev); + + qvirtqueue_cleanup(dev->bus, vq, t_alloc); +} + +static void pci_hotplug(void *obj, void *data, QGuestAllocator *t_alloc) +{ + QVirtioPCIDevice *dev1 = obj; + QVirtioPCIDevice *dev; + QTestState *qts = dev1->pdev->bus->qts; + + /* plug secondary disk */ + qtest_qmp_device_add(qts, "vhost-user-blk-pci", "drv1", + "{'addr': %s, 'chardev': 'char2'}", + stringify(PCI_SLOT_HP) ".0"); + + dev = virtio_pci_new(dev1->pdev->bus, + &(QPCIAddress) { .devfn = QPCI_DEVFN(PCI_SLOT_HP, 0) + }); + g_assert_nonnull(dev); + g_assert_cmpint(dev->vdev.device_type, ==, VIRTIO_ID_BLOCK); + qvirtio_pci_device_disable(dev); + qos_object_destroy((QOSGraphObject *)dev); + + /* unplug secondary disk */ + qpci_unplug_acpi_device_test(qts, "drv1", PCI_SLOT_HP); +} + +/* + * Check that setting the vring addr on a non-existent virtqueue does + * not crash. + */ +static void test_nonexistent_virtqueue(void *obj, void *data, + QGuestAllocator *t_alloc) +{ + QVhostUserBlkPCI *blk = obj; + QVirtioPCIDevice *pdev = &blk->pci_vdev; + QPCIBar bar0; + QPCIDevice *dev; + + dev = qpci_device_find(pdev->pdev->bus, QPCI_DEVFN(4, 0)); + g_assert(dev != NULL); + qpci_device_enable(dev); + + bar0 = qpci_iomap(dev, 0, NULL); + + qpci_io_writeb(dev, bar0, VIRTIO_PCI_QUEUE_SEL, 2); + qpci_io_writel(dev, bar0, VIRTIO_PCI_QUEUE_PFN, 1); + + g_free(dev); +} + +static const char *qtest_qemu_storage_daemon_binary(void) +{ + const char *qemu_storage_daemon_bin; + + qemu_storage_daemon_bin = getenv("QTEST_QEMU_STORAGE_DAEMON_BINARY"); + if (!qemu_storage_daemon_bin) { + fprintf(stderr, "Environment variable " + "QTEST_QEMU_STORAGE_DAEMON_BINARY required\n"); + exit(0); + } + + return qemu_storage_daemon_bin; +} + +static void drive_destroy(void *path) +{ + unlink(path); + g_free(path); + qos_invalidate_command_line(); +} + +static char *drive_create(void) +{ + int fd, ret; + /** vhost-user-blk won't recognize drive located in /tmp */ + char *t_path = g_strdup("qtest.XXXXXX"); + + /** Create a temporary raw image */ + fd = mkstemp(t_path); + g_assert_cmpint(fd, >=, 0); + ret = ftruncate(fd, TEST_IMAGE_SIZE); + g_assert_cmpint(ret, ==, 0); + close(fd); + + g_test_queue_destroy(drive_destroy, t_path); + return t_path; +} + +static char sock_path_tempate[] = "/tmp/qtest.vhost_user_blk.XXXXXX"; +static char qmp_sock_path_tempate[] = "/tmp/qtest.vhost_user_blk.qmp.XXXXXX"; + +static void quit_storage_daemon(void *qmp_test_state) +{ + const char quit_str[] = "{ 'execute': 'quit' }"; + + /* Before quiting storate-daemon, quit qemu to avoid dubious messages */ + qobject_unref(qtest_qmp(global_qtest, quit_str)); + + /* + * Give storage-daemon enough time to wake up&terminate + * vu_client_trip coroutine so the Coroutine object could + * be cleaned up. Otherwise LeakSanitizer would complain + * about memory leaks. + */ + g_usleep(1000); + + qobject_unref(qtest_qmp((QTestState *)qmp_test_state, quit_str)); + g_free(qmp_test_state); +} + +static char *start_vhost_user_blk(GString *cmd_line, int vus_instances) +{ + const char *vhost_user_blk_bin = qtest_qemu_storage_daemon_binary(); + int fd, qmp_fd, i; + QTestState *qmp_test_state; + gchar *img_path; + char *sock_path = NULL; + char *qmp_sock_path = g_strdup(qmp_sock_path_tempate); + GString *storage_daemon_command = g_string_new(NULL); + + qmp_fd = mkstemp(qmp_sock_path); + g_assert_cmpint(qmp_fd, >=, 0); + g_test_queue_destroy(drive_destroy, qmp_sock_path); + + g_string_append_printf(storage_daemon_command, + "exec %s " + "--chardev socket,id=qmp,path=%s,server,nowait --monitor chardev=qmp ", + vhost_user_blk_bin, qmp_sock_path); + + g_string_append_printf(cmd_line, + " -object memory-backend-memfd,id=mem,size=256M,share=on -M memory-backend=mem "); + + for (i = 0; i < vus_instances; i++) { + sock_path = g_strdup(sock_path_tempate); + fd = mkstemp(sock_path); + g_assert_cmpint(fd, >=, 0); + g_test_queue_destroy(drive_destroy, sock_path); + /* create image file */ + img_path = drive_create(); + g_string_append_printf(storage_daemon_command, + "--blockdev driver=file,node-name=disk%d,filename=%s " + "--export type=vhost-user-blk,id=disk%d,addr.type=unix,addr.path=%s," + "node-name=disk%i,writable=on ", + i, img_path, i, sock_path, i); + + g_string_append_printf(cmd_line, "-chardev socket,id=char%d,path=%s ", + i + 1, sock_path); + } + + g_test_message("starting vhost-user backend: %s", + storage_daemon_command->str); + pid_t pid = fork(); + if (pid == 0) { + execlp("/bin/sh", "sh", "-c", storage_daemon_command->str, NULL); + exit(1); + } + g_string_free(storage_daemon_command, true); + + qmp_test_state = qtest_create_state_with_qmp_fd( + qtest_socket_client(qmp_sock_path)); + /* + * Ask qemu-storage-daemon to quit so it + * will not block scripts/tap-driver.pl. + */ + g_test_queue_destroy(quit_storage_daemon, qmp_test_state); + + qobject_unref(qtest_qmp(qmp_test_state, "{'execute': 'qmp_capabilities'}")); + return sock_path; +} + +static void *vhost_user_blk_test_setup(GString *cmd_line, void *arg) +{ + start_vhost_user_blk(cmd_line, 1); + return arg; +} + +/* + * Setup for hotplug. + * + * Since vhost-user server only serves one vhost-user client one time, + * another exprot + * + */ +static void *vhost_user_blk_hotplug_test_setup(GString *cmd_line, void *arg) +{ + /* "-chardev socket,id=char2" is used for pci_hotplug*/ + start_vhost_user_blk(cmd_line, 2); + return arg; +} + +static void register_vhost_user_blk_test(void) +{ + QOSGraphTestOptions opts = { + .before = vhost_user_blk_test_setup, + }; + + /* + * tests for vhost-user-blk and vhost-user-blk-pci + * The tests are borrowed from tests/virtio-blk-test.c. But some tests + * regarding block_resize don't work for vhost-user-blk. + * vhost-user-blk device doesn't have -drive, so tests containing + * block_resize are also abandoned, + * - config + * - resize + */ + qos_add_test("basic", "vhost-user-blk", basic, &opts); + qos_add_test("indirect", "vhost-user-blk", indirect, &opts); + qos_add_test("idx", "vhost-user-blk-pci", idx, &opts); + qos_add_test("nxvirtq", "vhost-user-blk-pci", + test_nonexistent_virtqueue, &opts); + + opts.before = vhost_user_blk_hotplug_test_setup; + qos_add_test("hotplug", "vhost-user-blk-pci", pci_hotplug, &opts); +} + +libqos_init(register_vhost_user_blk_test); diff --git a/tests/qtest/libqos/meson.build b/tests/qtest/libqos/meson.build index 1cddf5bdaa..1f5c8f1053 100644 --- a/tests/qtest/libqos/meson.build +++ b/tests/qtest/libqos/meson.build @@ -32,6 +32,7 @@ libqos_srcs = files('../libqtest.c', 'virtio-9p.c', 'virtio-balloon.c', 'virtio-blk.c', + 'vhost-user-blk.c', 'virtio-mmio.c', 'virtio-net.c', 'virtio-pci.c', diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index c19f1c8503..23a70b4613 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -199,6 +199,7 @@ qos_test_ss.add( ) qos_test_ss.add(when: 'CONFIG_VIRTFS', if_true: files('virtio-9p-test.c')) qos_test_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user-test.c')) +qos_test_ss.add(when: ['CONFIG_LINUX', 'CONFIG_TOOLS'], if_true: files('vhost-user-blk-test.c')) tpmemu_files = ['tpm-emu.c', 'tpm-util.c', 'tpm-tests.c'] @@ -237,6 +238,7 @@ foreach dir : target_dirs endif qtest_env.set('G_TEST_DBUS_DAEMON', meson.source_root() / 'tests/dbus-vmstate-daemon.sh') qtest_env.set('QTEST_QEMU_BINARY', './qemu-system-' + target_base) + qtest_env.set('QTEST_QEMU_STORAGE_DAEMON_BINARY', './storage-daemon/qemu-storage-daemon') foreach test : target_qtests # Executables are shared across targets, declare them only the first time we From patchwork Tue Nov 3 14:35:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877837 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 AC28D92A for ; Tue, 3 Nov 2020 14:53:31 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6327D20757 for ; Tue, 3 Nov 2020 14:53:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="AaivHXYA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6327D20757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:44582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxgg-0003bp-CJ for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:53:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxPO-0005i7-VL for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55132) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxPJ-0006pP-AU for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414132; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=IbXx/en61PP6xw7L1bYEyVwqp2fnuXoDT6+6BHQY4zY=; b=AaivHXYANZ8zGd9oJoismtP34Gt0leVCi1H0kukjk030FFcjouk5UNlG5NQ8heeRpWPhep Zkn4pE3Dhx2pyRnpes20raF4x5UzeE0jljJ+CYry7EEotHbVSxGUiLHvMGl48sdcYN+ywx Kopsn9qhHVboCniQYp62YH+ty5iYjKc= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-383-Fzq3V4rBOxWaVR2fhDhz-g-1; Tue, 03 Nov 2020 09:35:30 -0500 X-MC-Unique: Fzq3V4rBOxWaVR2fhDhz-g-1 Received: by mail-wr1-f71.google.com with SMTP id i1so7874489wrb.18 for ; Tue, 03 Nov 2020 06:35:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=IbXx/en61PP6xw7L1bYEyVwqp2fnuXoDT6+6BHQY4zY=; b=ZvSA8fbNP/Jdb/TpOJmNMCU9Q2f0wm2H8zd1SiSZj8YwmFHPq/kJJZio92SaQv8vgd LK4XNHlyUuSnSUlj6P774U7Fz2x4vMU5I8cqwuV8Y8tVojK0YbXaBmvLDTeup1mmQUFQ 1LVlbmDHoizdCXIQQ7uyB1j41ogwRw3TSd+h3ZwKuJ2yCOU0evh1sd4nldHzGRHn5f97 3Bv67ilALKhxnrJHoBrCLHl0+/c6hZ4ytodoNepmikYK9mOGJnL9lT94EEoawMbqSbhf RwPjAmDadSAhNbV0+bTOAcR2ux3++wEWu9F+GH5UYYc7J4CvO0ITHbjlYw1ipnO4nIAy vVbQ== X-Gm-Message-State: AOAM5323tuFPyEpwG4uB67USu1vK8oaDyBiL0CB0ezvKJgLRLmL/0zfP ii/MSZt2/hN0qsP6lZdOwVg0FEHlXvXmmdlmSAEQFiNFSA5SWn0dfLZqrBXP6UvmoFRPbf1VtBa wvQDLKCfvNm/C7y4= X-Received: by 2002:a7b:cb09:: with SMTP id u9mr36113wmj.49.1604414128810; Tue, 03 Nov 2020 06:35:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJxC4ZbKj/jcljWm0fq7m/1sq4qa4x682Uj1E+j7prl6LunIeBajGnY4vlVzZphAxLMlE2nyiQ== X-Received: by 2002:a7b:cb09:: with SMTP id u9mr36086wmj.49.1604414128563; Tue, 03 Nov 2020 06:35:28 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id l16sm10974041wrr.83.2020.11.03.06.35.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:35:27 -0800 (PST) Date: Tue, 3 Nov 2020 09:35:26 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 33/38] tests/qtest: add multi-queue test case to vhost-user-blk-test Message-ID: <20201103142306.71782-34-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Peter Maydell , Thomas Huth , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Stefan Hajnoczi Signed-off-by: Stefan Hajnoczi Message-id: 20201001144604.559733-3-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi Message-Id: <20201027173528.213464-8-stefanha@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/qtest/vhost-user-blk-test.c | 81 +++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 5 deletions(-) diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk-test.c index e7e44f9bf0..31f2335f97 100644 --- a/tests/qtest/vhost-user-blk-test.c +++ b/tests/qtest/vhost-user-blk-test.c @@ -559,6 +559,67 @@ static void pci_hotplug(void *obj, void *data, QGuestAllocator *t_alloc) qpci_unplug_acpi_device_test(qts, "drv1", PCI_SLOT_HP); } +static void multiqueue(void *obj, void *data, QGuestAllocator *t_alloc) +{ + QVirtioPCIDevice *pdev1 = obj; + QVirtioDevice *dev1 = &pdev1->vdev; + QVirtioPCIDevice *pdev8; + QVirtioDevice *dev8; + QTestState *qts = pdev1->pdev->bus->qts; + uint64_t features; + uint16_t num_queues; + + /* + * The primary device has 1 queue and VIRTIO_BLK_F_MQ is not enabled. The + * VIRTIO specification allows VIRTIO_BLK_F_MQ to be enabled when there is + * only 1 virtqueue, but --device vhost-user-blk-pci doesn't do this (which + * is also spec-compliant). + */ + features = qvirtio_get_features(dev1); + g_assert_cmpint(features & (1u << VIRTIO_BLK_F_MQ), ==, 0); + features = features & ~(QVIRTIO_F_BAD_FEATURE | + (1u << VIRTIO_RING_F_INDIRECT_DESC) | + (1u << VIRTIO_F_NOTIFY_ON_EMPTY) | + (1u << VIRTIO_BLK_F_SCSI)); + qvirtio_set_features(dev1, features); + + /* Hotplug a secondary device with 8 queues */ + qtest_qmp_device_add(qts, "vhost-user-blk-pci", "drv1", + "{'addr': %s, 'chardev': 'char2', 'num-queues': 8}", + stringify(PCI_SLOT_HP) ".0"); + + pdev8 = virtio_pci_new(pdev1->pdev->bus, + &(QPCIAddress) { + .devfn = QPCI_DEVFN(PCI_SLOT_HP, 0) + }); + g_assert_nonnull(pdev8); + g_assert_cmpint(pdev8->vdev.device_type, ==, VIRTIO_ID_BLOCK); + + qos_object_start_hw(&pdev8->obj); + + dev8 = &pdev8->vdev; + features = qvirtio_get_features(dev8); + g_assert_cmpint(features & (1u << VIRTIO_BLK_F_MQ), + ==, + (1u << VIRTIO_BLK_F_MQ)); + features = features & ~(QVIRTIO_F_BAD_FEATURE | + (1u << VIRTIO_RING_F_INDIRECT_DESC) | + (1u << VIRTIO_F_NOTIFY_ON_EMPTY) | + (1u << VIRTIO_BLK_F_SCSI) | + (1u << VIRTIO_BLK_F_MQ)); + qvirtio_set_features(dev8, features); + + num_queues = qvirtio_config_readw(dev8, + offsetof(struct virtio_blk_config, num_queues)); + g_assert_cmpint(num_queues, ==, 8); + + qvirtio_pci_device_disable(pdev8); + qos_object_destroy(&pdev8->obj); + + /* unplug secondary disk */ + qpci_unplug_acpi_device_test(qts, "drv1", PCI_SLOT_HP); +} + /* * Check that setting the vring addr on a non-existent virtqueue does * not crash. @@ -643,7 +704,8 @@ static void quit_storage_daemon(void *qmp_test_state) g_free(qmp_test_state); } -static char *start_vhost_user_blk(GString *cmd_line, int vus_instances) +static char *start_vhost_user_blk(GString *cmd_line, int vus_instances, + int num_queues) { const char *vhost_user_blk_bin = qtest_qemu_storage_daemon_binary(); int fd, qmp_fd, i; @@ -675,8 +737,8 @@ static char *start_vhost_user_blk(GString *cmd_line, int vus_instances) g_string_append_printf(storage_daemon_command, "--blockdev driver=file,node-name=disk%d,filename=%s " "--export type=vhost-user-blk,id=disk%d,addr.type=unix,addr.path=%s," - "node-name=disk%i,writable=on ", - i, img_path, i, sock_path, i); + "node-name=disk%i,writable=on,num-queues=%d ", + i, img_path, i, sock_path, i, num_queues); g_string_append_printf(cmd_line, "-chardev socket,id=char%d,path=%s ", i + 1, sock_path); @@ -705,7 +767,7 @@ static char *start_vhost_user_blk(GString *cmd_line, int vus_instances) static void *vhost_user_blk_test_setup(GString *cmd_line, void *arg) { - start_vhost_user_blk(cmd_line, 1); + start_vhost_user_blk(cmd_line, 1, 1); return arg; } @@ -719,7 +781,13 @@ static void *vhost_user_blk_test_setup(GString *cmd_line, void *arg) static void *vhost_user_blk_hotplug_test_setup(GString *cmd_line, void *arg) { /* "-chardev socket,id=char2" is used for pci_hotplug*/ - start_vhost_user_blk(cmd_line, 2); + start_vhost_user_blk(cmd_line, 2, 1); + return arg; +} + +static void *vhost_user_blk_multiqueue_test_setup(GString *cmd_line, void *arg) +{ + start_vhost_user_blk(cmd_line, 2, 8); return arg; } @@ -746,6 +814,9 @@ static void register_vhost_user_blk_test(void) opts.before = vhost_user_blk_hotplug_test_setup; qos_add_test("hotplug", "vhost-user-blk-pci", pci_hotplug, &opts); + + opts.before = vhost_user_blk_multiqueue_test_setup; + qos_add_test("multiqueue", "vhost-user-blk-pci", multiqueue, &opts); } libqos_init(register_vhost_user_blk_test); From patchwork Tue Nov 3 14:35:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877885 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 E89D2921 for ; Tue, 3 Nov 2020 15:00:34 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9EA0C20757 for ; Tue, 3 Nov 2020 15:00:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SVv42ByH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9EA0C20757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:39880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxnV-0005Da-Lp for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 10:00:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33824) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxPj-0005uG-Lk for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:59 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:30307) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxPg-0006ye-Up for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414155; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=TD7SW6oID+mQnZFy+V2Ba30n404JJ+wGVVREK/DvNQg=; b=SVv42ByHYUU0gMHvCE/nKGUepcUaT1ragNRXVdFaeJ+1XWHOmW3oxQeIJQZLAq5e/z4i8i dB5KPyp+KxolN6PyVa6E0RuKwv/emI3PiizBz48vmkNLinAT5dPPiGSRL0/k+dIJv5B7H1 cCRT/oVm3KcAU4AZlkSC+L8kFMQRtTc= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-260-1DJSvekjP_6WegRXWGz23w-1; Tue, 03 Nov 2020 09:35:33 -0500 X-MC-Unique: 1DJSvekjP_6WegRXWGz23w-1 Received: by mail-wm1-f71.google.com with SMTP id y26so347540wmj.7 for ; Tue, 03 Nov 2020 06:35:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=TD7SW6oID+mQnZFy+V2Ba30n404JJ+wGVVREK/DvNQg=; b=EoTt7vPRYqdH5ogDbmp58hPXlfXgoJiPZZfCEQD09bErU3aTZPztQgkROgOGB+5voH 7RLU6LCmEEAFvuv2VL6OSnNhIukVSUw2n0AkXx13tXYVMqz1+1z1+FughdmYgt0GraQq a8z1ksTl1Jj/x9nv1/97dg5cs8IBPMx2LQkEsLRWXa2A0JB7zEyEKDlwGH2Lu1VgZ8tB MXew6sNbGuVexD9zfosthET9YTcM3ow634sdw6R7luyE+pmUeBgMnIeVyTb3vw1E3H4o rE+KaqoEBw79V06Envls6bJex5F7+pf79y2mroaDBvXzNsjSYxz+J92tm1SZflTOO5+t uRAQ== X-Gm-Message-State: AOAM5305mDp9A199UMY6GhEhu8jUklUdhNTFGVSSwL84h1jq/+54OlDD iBCvZRxaOmp0bzpEX5mNVnam/pFsmKeaw2Bp9Tp20LyEav+hZRXqsvUIt6Z9rPUP1sLA2LVx3RF 7+dYSPDKwy6+7A7w= X-Received: by 2002:adf:e8cb:: with SMTP id k11mr26679277wrn.91.1604414131286; Tue, 03 Nov 2020 06:35:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwztaqG09Ip5CpZXK94nMkqYjG1GdMbVOjL/YYa/YfVz66GAWws07A1GrfH10tClGMzPKmsew== X-Received: by 2002:adf:e8cb:: with SMTP id k11mr26679259wrn.91.1604414131134; Tue, 03 Nov 2020 06:35:31 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id t1sm25553923wrs.48.2020.11.03.06.35.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:35:30 -0800 (PST) Date: Tue, 3 Nov 2020 09:35:28 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 34/38] libqtest: add qtest_socket_server() Message-ID: <20201103142306.71782-35-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Peter Maydell , Thomas Huth , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Stefan Hajnoczi There is a qtest_socket_client() API. Add an equivalent qtest_socket_server() API that returns a new UNIX domain socket in the listen state. The code for this was already there but only used internally in init_socket(). Signed-off-by: Stefan Hajnoczi Message-Id: <20201027173528.213464-9-stefanha@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/qtest/libqos/libqtest.h | 8 +++++++ tests/qtest/libqtest.c | 40 ++++++++++++++++++++--------------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/tests/qtest/libqos/libqtest.h b/tests/qtest/libqos/libqtest.h index 241b5f89fb..699be8c2a2 100644 --- a/tests/qtest/libqos/libqtest.h +++ b/tests/qtest/libqos/libqtest.h @@ -132,6 +132,14 @@ void qtest_qmp_send(QTestState *s, const char *fmt, ...) void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...) GCC_FMT_ATTR(2, 3); +/** + * qtest_socket_server: + * @socket_path: the UNIX domain socket path + * + * Create and return a listen socket file descriptor, or abort on failure. + */ +int qtest_socket_server(const char *socket_path); + /** * qtest_socket_client: * @server_socket_path: the socket server's path diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index ab34075f2b..d652ffc90d 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -82,24 +82,8 @@ static void qtest_client_set_rx_handler(QTestState *s, QTestRecvFn recv); static int init_socket(const char *socket_path) { - struct sockaddr_un addr; - int sock; - int ret; - - sock = socket(PF_UNIX, SOCK_STREAM, 0); - g_assert_cmpint(sock, !=, -1); - - addr.sun_family = AF_UNIX; - snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", socket_path); + int sock = qtest_socket_server(socket_path); qemu_set_cloexec(sock); - - do { - ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr)); - } while (ret == -1 && errno == EINTR); - g_assert_cmpint(ret, !=, -1); - ret = listen(sock, 1); - g_assert_cmpint(ret, !=, -1); - return sock; } @@ -638,6 +622,28 @@ QTestState *qtest_create_state_with_qmp_fd(int fd) return qmp_test_state; } +int qtest_socket_server(const char *socket_path) +{ + struct sockaddr_un addr; + int sock; + int ret; + + sock = socket(PF_UNIX, SOCK_STREAM, 0); + g_assert_cmpint(sock, !=, -1); + + addr.sun_family = AF_UNIX; + snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", socket_path); + + do { + ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr)); + } while (ret == -1 && errno == EINTR); + g_assert_cmpint(ret, !=, -1); + ret = listen(sock, 1); + g_assert_cmpint(ret, !=, -1); + + return sock; +} + int qtest_socket_client(char *server_socket_path) { struct sockaddr_un serv_addr; From patchwork Tue Nov 3 14:35:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877841 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 ADEB86A2 for ; Tue, 3 Nov 2020 14:54:44 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 649EF20757 for ; Tue, 3 Nov 2020 14:54:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="a8a8qtXb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 649EF20757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:49790 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxhq-0005mc-7y for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:54:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33728) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxPc-0005mt-8R for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50081) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxPQ-0006ul-6h for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414139; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=oAjLZ11EwsHXoMOOACL8j6jIH95zMRiiieEROhG5SCc=; b=a8a8qtXb/f+L4JFh2dWjR/dVtSmXARhBRxYzdeCDbV7K0G8UWcsNHooUIy081EhxYXGuPm XFH2zg6YJ1t+9RsvaG5J7I83A1LmZGeCiQrYwGR1/kmGSdiTo6V7YigUTlfv8bN/iSf8qh gwO9zCmpQhUnr5bepmLC1pC4g5gZ5EE= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-315-mmGjxVFvN6-tbNL8oTFi1A-1; Tue, 03 Nov 2020 09:35:35 -0500 X-MC-Unique: mmGjxVFvN6-tbNL8oTFi1A-1 Received: by mail-wm1-f72.google.com with SMTP id t21so2696092wmt.8 for ; Tue, 03 Nov 2020 06:35:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=oAjLZ11EwsHXoMOOACL8j6jIH95zMRiiieEROhG5SCc=; b=uOnzlmpOfMAfd7nVaM4lkmtsOLJzJmE7NTd2Gmb8cSh+35GrLFWwAGFFu1uI64/5UF Uk4n/kPLXZvjmPTQl1XybtgzAIUo6totZKLV0UXcy6z70Ee4kCEk3DsIpW2N77xaRFhU +iXJ0xt/1u9yJ7fuTECjnOiKiHIXg4gMox9YbOF/fM1titi+2xs1Hkl4DpPxt5SkKHJA cG0T8vCUoQU5fzIK/5HrZC6A04Qc8xIDwsYLTIZEGfcyVVG9VmQ26+AMJKk3QDoVqGnR 3gEgzf453NVcsdg9F67lExelDHdMFRWccATy5/84nB/xFr51h4+Pp8LXkkZca05Tb+x3 pvmg== X-Gm-Message-State: AOAM5326YGiS0s9bzMoMENVoMy5ZG/thr3+PiQymLqZrf9eveG3gZWz6 aN5SrSyrVuEeshFSGaU351nzRCD8cK/4+fWG9xhl8yd6VBYb1FsDzyp+4c9Wwp1jaREyQ5kaTkH pcObD84onVek167o= X-Received: by 2002:a1c:2583:: with SMTP id l125mr80540wml.50.1604414133758; Tue, 03 Nov 2020 06:35:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJyyANNMlJ4QNIKoDRnB7sRi+l/PB/29ywBQgYzrmXnCllCcepBuvfnXCC8D391ReiOBPZ87gw== X-Received: by 2002:a1c:2583:: with SMTP id l125mr80523wml.50.1604414133600; Tue, 03 Nov 2020 06:35:33 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id a199sm3293038wmd.8.2020.11.03.06.35.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:35:32 -0800 (PST) Date: Tue, 3 Nov 2020 09:35:31 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 35/38] vhost-user-blk-test: rename destroy_drive() to destroy_file() Message-ID: <20201103142306.71782-36-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Peter Maydell , Thomas Huth , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Stefan Hajnoczi The function is used not just for image files but also for UNIX domain sockets (QMP monitor and vhost-user-blk). Reflect that in the name. Signed-off-by: Stefan Hajnoczi Message-Id: <20201027173528.213464-10-stefanha@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/qtest/vhost-user-blk-test.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk-test.c index 31f2335f97..f05f14c192 100644 --- a/tests/qtest/vhost-user-blk-test.c +++ b/tests/qtest/vhost-user-blk-test.c @@ -658,7 +658,8 @@ static const char *qtest_qemu_storage_daemon_binary(void) return qemu_storage_daemon_bin; } -static void drive_destroy(void *path) +/* g_test_queue_destroy() cleanup function for files */ +static void destroy_file(void *path) { unlink(path); g_free(path); @@ -678,7 +679,7 @@ static char *drive_create(void) g_assert_cmpint(ret, ==, 0); close(fd); - g_test_queue_destroy(drive_destroy, t_path); + g_test_queue_destroy(destroy_file, t_path); return t_path; } @@ -717,7 +718,7 @@ static char *start_vhost_user_blk(GString *cmd_line, int vus_instances, qmp_fd = mkstemp(qmp_sock_path); g_assert_cmpint(qmp_fd, >=, 0); - g_test_queue_destroy(drive_destroy, qmp_sock_path); + g_test_queue_destroy(destroy_file, qmp_sock_path); g_string_append_printf(storage_daemon_command, "exec %s " @@ -731,7 +732,7 @@ static char *start_vhost_user_blk(GString *cmd_line, int vus_instances, sock_path = g_strdup(sock_path_tempate); fd = mkstemp(sock_path); g_assert_cmpint(fd, >=, 0); - g_test_queue_destroy(drive_destroy, sock_path); + g_test_queue_destroy(drive_file, sock_path); /* create image file */ img_path = drive_create(); g_string_append_printf(storage_daemon_command, From patchwork Tue Nov 3 14:35:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877873 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 D659B6A2 for ; Tue, 3 Nov 2020 14:57:14 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6096B20757 for ; Tue, 3 Nov 2020 14:57:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="by6Qp17Z" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6096B20757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:57906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxkH-0000sX-B9 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:57:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxPd-0005nw-3P for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22110) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxPT-0006vm-EJ for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=rcR22V11VaSxRGTj44Apo/6OVNtdiu3pQdLqlX7HYbs=; b=by6Qp17ZBff0EDP4UmwQTZKX4W2MmXkfnygUP+34iWfqsYwIuthSczxFTsJNRK0GErdECq 6nBvoQ9Xli1KzUJpvH9ZWLcB6tedVnHgp/EroTKw/dLZRf8yUZpcOhWdPRqNQnxNDEICz7 ce5DEJMVBsxAx16PWB+kfORiRaCkfOk= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-369-wHBijEJFNTCOKjFUpp4FdQ-1; Tue, 03 Nov 2020 09:35:37 -0500 X-MC-Unique: wHBijEJFNTCOKjFUpp4FdQ-1 Received: by mail-wr1-f72.google.com with SMTP id h8so7919474wrt.9 for ; Tue, 03 Nov 2020 06:35:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=rcR22V11VaSxRGTj44Apo/6OVNtdiu3pQdLqlX7HYbs=; b=kaEUhZOL1OvGyMTxKZUx4rF8Ag4oCZyM3+d+TFF5fbWnJXUJNIklgjDUF+2hzcfqZe pDtj+geQH28OpkvlAjqVIWoAckCjjGm5jTLBiYaAtiuiaSLt1YtAm2PoODI5ULMVaQDB pKGeFLaJUVrIP+ZC5IKIfnt2U8ke0uL9gFChtqdl8FrSwB9A2TjTgRwhoLWPGXM5QJE3 wY5kxMcjISJ4+qCAv4YFzhjSmWLzKYIOVRlStaRgk6+i+DR708Lw8inEqqObDljD2xxH SgQfsU9Fb1+vBDYIbaKDhzBZ/WVBb/VV3M9aZmEnWi9WQKYf6Wtd02s/BW+7vkckblIt jAhg== X-Gm-Message-State: AOAM531Fi64fmwojbxjcjb1IznRZ8TtjUx1SGBf0dGJAH/ZpBqKqTMq3 WauWSIHzgCY7CTzWBJdKsNtDAQR29QEQ/EFr+P9np51K5jE+LweeSirQQrJ742P29L/hL3eOGS3 dWCUlDMUSputKolE= X-Received: by 2002:a7b:c3d2:: with SMTP id t18mr74311wmj.112.1604414136240; Tue, 03 Nov 2020 06:35:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJxaeOPGVrJl8XK6+gPd8MFdygPE5F3FcdAmUH4JOkHIQmkR+9ZPJUdSX9+z0v5X5T0CaUuzOA== X-Received: by 2002:a7b:c3d2:: with SMTP id t18mr74291wmj.112.1604414136060; Tue, 03 Nov 2020 06:35:36 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id o7sm26452454wrp.23.2020.11.03.06.35.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:35:35 -0800 (PST) Date: Tue, 3 Nov 2020 09:35:33 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 36/38] vhost-user-blk-test: close fork child file descriptors Message-ID: <20201103142306.71782-37-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Peter Maydell , Thomas Huth , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Stefan Hajnoczi Do not leave stdin, stdout, stderr open after fork. stdout is the tap-driver.pl pipe. If we keep the pipe open then tap-driver.pl will not detect that qos-test has terminated and it will hang. Signed-off-by: Stefan Hajnoczi Message-Id: <20201027173528.213464-11-stefanha@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/qtest/vhost-user-blk-test.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk-test.c index f05f14c192..15daf8ccbc 100644 --- a/tests/qtest/vhost-user-blk-test.c +++ b/tests/qtest/vhost-user-blk-test.c @@ -749,6 +749,17 @@ static char *start_vhost_user_blk(GString *cmd_line, int vus_instances, storage_daemon_command->str); pid_t pid = fork(); if (pid == 0) { + /* + * Close standard file descriptors so tap-driver.pl pipe detects when + * our parent terminates. + */ + close(0); + close(1); + close(2); + open("/dev/null", O_RDONLY); + open("/dev/null", O_WRONLY); + open("/dev/null", O_WRONLY); + execlp("/bin/sh", "sh", "-c", storage_daemon_command->str, NULL); exit(1); } From patchwork Tue Nov 3 14:35:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877875 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 2C1226A2 for ; Tue, 3 Nov 2020 14:57:51 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DAA7020757 for ; Tue, 3 Nov 2020 14:57:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OMG+B2rh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DAA7020757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:59782 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxkr-0001ez-S7 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 09:57:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxPd-0005nq-0D for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46209) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxPV-0006wa-3E for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414142; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=L0BE6BIYyp008EuFnEKAYjzMhrYRUbO0ZaRk54gDh4k=; b=OMG+B2rhsspzUWUJutwO30mgasxD2V66lSpxJCa8l/vM0ZZhp1WZF92VzZyURp4OKZhEEU SmSqBgJUm5hEMm9SxVtNcTWjcIQBKt5aRJWDSdjS4j9ryvRkuKGbwanySUVVxQqUXfackn n+c9f4lJgYmstlVe0mZobkcTLmuAoxE= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-457-HYsJju8uPGSueYleCp7IhA-1; Tue, 03 Nov 2020 09:35:40 -0500 X-MC-Unique: HYsJju8uPGSueYleCp7IhA-1 Received: by mail-wm1-f70.google.com with SMTP id c10so3822637wmh.6 for ; Tue, 03 Nov 2020 06:35:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=L0BE6BIYyp008EuFnEKAYjzMhrYRUbO0ZaRk54gDh4k=; b=Uv9SCgNVBs2qBJ82g4TDQR6vawtfLd6E56AxMI2cK/Z1gA070CdnUbK1/R1ESjZtNk wo/XWpyyzLIqJ9x5Bkurrrtxnwn8WcXd8pJYu7p1mzBCYg5k4qqAL+b2fOR8+mZeymB9 FtI34PXGV2xRdz9QYwMyZNsIEi4IvfmFyw5O2kc1cMEjzeyZZ70b5wSRXf3VPncgJ8bg KwB5PKt7kpKlWKniawZpUflcDMSO7a77cB/An18xNaJm0vQTUvb/e3fdHT6qvqTH5ERO 1hMrQrBhy7D+idvx9ntfiN+9olhDX6phvqC+veMdT+00j/jzrQRIBe4nzbVtDZBe8wo+ BxhQ== X-Gm-Message-State: AOAM5306ssHSNbLbzxyin1i91csHqKaefh04ehvYTKKLlfHqTYZk+Wdn X1/AjwZhojIYMA6ppbviV0Hy81+8FS6i1oqdOhQq8RfYwXVX/IKfEF/PKXdvxU/GXKh7b7YsXWH RFmTYR7Ujb/KUYFs= X-Received: by 2002:a5d:4987:: with SMTP id r7mr25151041wrq.327.1604414138892; Tue, 03 Nov 2020 06:35:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJw6eT8xSIAkLFdGF44qCEw81GfoHqealWC0BvlZUQ7Lze2P7OMlEvPznNZ+X2OmMquKrpWvLw== X-Received: by 2002:a5d:4987:: with SMTP id r7mr25151026wrq.327.1604414138695; Tue, 03 Nov 2020 06:35:38 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id s202sm3127156wme.39.2020.11.03.06.35.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:35:37 -0800 (PST) Date: Tue, 3 Nov 2020 09:35:36 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 37/38] vhost-user-blk-test: drop unused return value Message-ID: <20201103142306.71782-38-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Peter Maydell , Thomas Huth , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Stefan Hajnoczi The sock_path return value was unused and bogus (it doesn't make sense when there are multiple drives because only the last path is arbitrarily returned). Signed-off-by: Stefan Hajnoczi Message-Id: <20201027173528.213464-12-stefanha@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/qtest/vhost-user-blk-test.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk-test.c index 15daf8ccbc..0d056cc189 100644 --- a/tests/qtest/vhost-user-blk-test.c +++ b/tests/qtest/vhost-user-blk-test.c @@ -705,8 +705,8 @@ static void quit_storage_daemon(void *qmp_test_state) g_free(qmp_test_state); } -static char *start_vhost_user_blk(GString *cmd_line, int vus_instances, - int num_queues) +static void start_vhost_user_blk(GString *cmd_line, int vus_instances, + int num_queues) { const char *vhost_user_blk_bin = qtest_qemu_storage_daemon_binary(); int fd, qmp_fd, i; @@ -774,7 +774,6 @@ static char *start_vhost_user_blk(GString *cmd_line, int vus_instances, g_test_queue_destroy(quit_storage_daemon, qmp_test_state); qobject_unref(qtest_qmp(qmp_test_state, "{'execute': 'qmp_capabilities'}")); - return sock_path; } static void *vhost_user_blk_test_setup(GString *cmd_line, void *arg) From patchwork Tue Nov 3 14:35:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 11877899 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 7FC586A2 for ; Tue, 3 Nov 2020 15:07:08 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 13D02221FB for ; Tue, 3 Nov 2020 15:07:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="jBHzaGJK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 13D02221FB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:56390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZxtr-000467-1O for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Nov 2020 10:07:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33806) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZxPh-0005rK-78 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:34358) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kZxPc-0006wq-M8 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 09:35:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604414145; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vTElEagYE/6ac5+wAhrYnP4rDr3IItx6R4ENpWim+c0=; b=jBHzaGJKwfq50wPvIHh57SB+fkM4hEq04DboAi9INWxctQ7N1mFJf7tsoLaZ6esZLtyIek JhQgS4Vx2mT2kfpCm+4wTH0/qvpIA1zdSLYQHV3rh7TQ8A0g3BRJt84NF15APt9z3Riz1P 0bZ0C1mJl/CRczrj/kKJRiQqWWQIBBM= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-287-EW7PwaYcMGqKPIKrSsRVWg-1; Tue, 03 Nov 2020 09:35:42 -0500 X-MC-Unique: EW7PwaYcMGqKPIKrSsRVWg-1 Received: by mail-wr1-f69.google.com with SMTP id q15so7881424wrw.8 for ; Tue, 03 Nov 2020 06:35:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=vTElEagYE/6ac5+wAhrYnP4rDr3IItx6R4ENpWim+c0=; b=QWV1g7ZR3ezFrdg5DfL0yztDLPijHBb3YQXqHxYD2Cx9Leb4AXPRJedHH73BCDgXtN 0XaMkPH/AwQACTQmAvKKQzx9TZbyISrg9UOJwYwguVuwUoYaBf2XnhjtiyGomjUHVh8M vSarrxtkKMerdlAqyee01763GcPNekDgGKVVXQGoWTm91fE1Li/yrNhqUcjw9QFa2hBy 691TGI4nb98IMZ/JdzOGRZhW7+LozNBQFs0ppTIhiCU3mJCvJRtQwXdL+MSliXhYXcBF ghuJb1WtydkHdC2dRCUW5t2ZdoQTcyhF4cojNZ25TTLQRM/+tjeToN1HeMNcNftlEVW4 I2tg== X-Gm-Message-State: AOAM5321gC4gvjSktC01MFFFVYeShslYj0GwrVZRUW57VyQ3yM0Cqgc/ YVBJil1jAb4tAZ/5TunsrOuJEkibu+CI+2/HS4p6TR11BCFK7ruKCbVLd311OWIvPYKUTgPjz+F uz3X9I6RLTwZ4x0k= X-Received: by 2002:adf:e650:: with SMTP id b16mr27420421wrn.350.1604414141418; Tue, 03 Nov 2020 06:35:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJwMMNMGHZbO4LF+o7ud2HSluu0JBpRtCv3NEdYmUxzmzTThKN8EesY71rMtVjtNyP0xHDl/aw== X-Received: by 2002:adf:e650:: with SMTP id b16mr27420400wrn.350.1604414141204; Tue, 03 Nov 2020 06:35:41 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id f3sm269918wrw.81.2020.11.03.06.35.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 06:35:40 -0800 (PST) Date: Tue, 3 Nov 2020 09:35:39 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 38/38] vhost-user-blk-test: fix races by using fd passing Message-ID: <20201103142306.71782-39-mst@redhat.com> References: <20201103142306.71782-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201103142306.71782-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Peter Maydell , Thomas Huth , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Stefan Hajnoczi Pass the QMP and vhost-user-blk server sockets as file descriptors. That way the sockets are already open and in a listen state when the QEMU process is launched. This solves the race with qemu-storage-daemon startup where the UNIX domain sockets may not be ready yet when QEMU attempts to connect. It also saves us sleeping for 1 second if the qemu-storage-daemon QMP socket is not ready yet. Signed-off-by: Stefan Hajnoczi Message-Id: <20201027173528.213464-13-stefanha@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/qtest/vhost-user-blk-test.c | 42 +++++++++++++++++++------------ 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk-test.c index 0d056cc189..9589f90b14 100644 --- a/tests/qtest/vhost-user-blk-test.c +++ b/tests/qtest/vhost-user-blk-test.c @@ -683,8 +683,22 @@ static char *drive_create(void) return t_path; } -static char sock_path_tempate[] = "/tmp/qtest.vhost_user_blk.XXXXXX"; -static char qmp_sock_path_tempate[] = "/tmp/qtest.vhost_user_blk.qmp.XXXXXX"; +static char *create_listen_socket(int *fd) +{ + int tmp_fd; + char *path; + + /* No race because our pid makes the path unique */ + path = g_strdup_printf("/tmp/qtest-%d-sock.XXXXXX", getpid()); + tmp_fd = mkstemp(path); + g_assert_cmpint(tmp_fd, >=, 0); + close(tmp_fd); + unlink(path); + + *fd = qtest_socket_server(path); + g_test_queue_destroy(destroy_file, path); + return path; +} static void quit_storage_daemon(void *qmp_test_state) { @@ -709,37 +723,33 @@ static void start_vhost_user_blk(GString *cmd_line, int vus_instances, int num_queues) { const char *vhost_user_blk_bin = qtest_qemu_storage_daemon_binary(); - int fd, qmp_fd, i; + int qmp_fd, i; QTestState *qmp_test_state; gchar *img_path; - char *sock_path = NULL; - char *qmp_sock_path = g_strdup(qmp_sock_path_tempate); + char *qmp_sock_path; GString *storage_daemon_command = g_string_new(NULL); - qmp_fd = mkstemp(qmp_sock_path); - g_assert_cmpint(qmp_fd, >=, 0); - g_test_queue_destroy(destroy_file, qmp_sock_path); + qmp_sock_path = create_listen_socket(&qmp_fd); g_string_append_printf(storage_daemon_command, "exec %s " - "--chardev socket,id=qmp,path=%s,server,nowait --monitor chardev=qmp ", - vhost_user_blk_bin, qmp_sock_path); + "--chardev socket,id=qmp,fd=%d,server,nowait --monitor chardev=qmp ", + vhost_user_blk_bin, qmp_fd); g_string_append_printf(cmd_line, " -object memory-backend-memfd,id=mem,size=256M,share=on -M memory-backend=mem "); for (i = 0; i < vus_instances; i++) { - sock_path = g_strdup(sock_path_tempate); - fd = mkstemp(sock_path); - g_assert_cmpint(fd, >=, 0); - g_test_queue_destroy(drive_file, sock_path); + int fd; + char *sock_path = create_listen_socket(&fd); + /* create image file */ img_path = drive_create(); g_string_append_printf(storage_daemon_command, "--blockdev driver=file,node-name=disk%d,filename=%s " - "--export type=vhost-user-blk,id=disk%d,addr.type=unix,addr.path=%s," + "--export type=vhost-user-blk,id=disk%d,addr.type=fd,addr.str=%d," "node-name=disk%i,writable=on,num-queues=%d ", - i, img_path, i, sock_path, i, num_queues); + i, img_path, i, fd, i, num_queues); g_string_append_printf(cmd_line, "-chardev socket,id=char%d,path=%s ", i + 1, sock_path);