Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp765237ybj; Thu, 7 May 2020 07:11:07 -0700 (PDT) X-Google-Smtp-Source: APiQypLDtVfyzrVAN53rXOruKJ9ZHO08Kp796qIJMJJllXgCaVUHCec9k5A0Z6/oJ1v0ykLxtYI6 X-Received: by 2002:a17:906:4995:: with SMTP id p21mr11822506eju.19.1588860666942; Thu, 07 May 2020 07:11:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588860666; cv=none; d=google.com; s=arc-20160816; b=BCkPF4G62fk/Gkd2FxFtgiilAzCiFRskXuigUB5UBqanxtPgP/x9iZuK66WEebPiwQ xA99NOG7xIi5+JbzJolXh+GDF11RcQNdO5cXTvylOS13BTkjgs2SBNQRqrrHpMtuI0BA 2j7lGJWWFNZ1GORXVZwVYG4wOZQFjUF2AfzmzdHdPBE8FX7mF0K8guGwC3NW5AnAgQ6C JvLJzU0owiGLUjTNiKT7E1KPyH0grC2lxfuHk7Mf97HJxkl7UzuzQr0GbdWkCR4z4+kg lz0y0o3hmAGGnGybH/fwDof8yllEiiUfq8jZIW4HOy4/Q4bJYbPzq/8vy3FOaR5cFEOw VEjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=+aQ+iWJtTlzvsD3O2ITCsYtNNFRLe3AecxY3imabsd8=; b=s5DmBrwaydscskCZRUWJcPt1FE8GQD7M1zYE5XXiMryl2uDFz5wsQdMovlSpiX3m3s tn6AkKIQj62xYwsgwZo5660HmX7FFUZXIyzzXd1srCz9lDvZLzhGWUauOxmsQSFt9DqG JdOtt/wQStNMHzPFMsy1qKlBp5ES1jgLF2P4P34K34viSdryqiDSOHfk+pcFZ9uenf8c 7GlK5dvzEpi2PDL01BiFG9UCH7vYaOEmg7RFI31PFbBfyhfIUhvpTEwJ5RBeVLCZD3eZ dd2rg5l3D6OPBXlcZVk9Z2oLx/jPlDYsEBqW91u+CXOkx14c45VCiOr5WBZeCdJDWfYR fR1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=khDXSpGw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t23si3199666edw.78.2020.05.07.07.10.41; Thu, 07 May 2020 07:11:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=khDXSpGw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726519AbgEGOGn (ORCPT + 99 others); Thu, 7 May 2020 10:06:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725947AbgEGOGn (ORCPT ); Thu, 7 May 2020 10:06:43 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A048CC05BD43; Thu, 7 May 2020 07:06:42 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id r26so6994561wmh.0; Thu, 07 May 2020 07:06:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+aQ+iWJtTlzvsD3O2ITCsYtNNFRLe3AecxY3imabsd8=; b=khDXSpGwapNMmlhylLz/6Mk+CnEra5lCL0OPUi5q+Cnsa2lM8MXNpd1HZmI8dFLYaG tcoQ/F+JUev7CrL6JmDD59WWH+9bI4xjyVlHnJTicHX4gkS/n6UmmE/w30RUVEkh+ldr Oj1VBZjIapPdI1MVHLg0zxJAsHPrv+KcQdkVgs59fvqvvCd7jmH2cHVYV3VNGOxE0REO NA3sk0pReUia0BZCdo8JLIemI6UoHAdkPJHE3E5SkFRVygRsdL2xdrqNUbQusyAjH7iB N7mu3/YcHm6ae+ttcfv2c2ZH6AY/YaBywSUHBZrCfWRwf5e4Agv4DCLtViaPIXGX33X9 Uiog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+aQ+iWJtTlzvsD3O2ITCsYtNNFRLe3AecxY3imabsd8=; b=tvSt6gzj+SPs2kME9TpUQwPwyKTVG896A+alTD1wK+3QLFbPx6w3UgN6QpJdcsIo4a XiRDARq4UogPiP0rRwTjz+KbJmNr1w3HY8Iu6zOHhSNhEnl/K2q8dvNYX5JTwQKyGMA1 fRSTNjCHKMrIt57eZFJX5/bsMYkcUw5OzyskBQNRlCZEMAsSPhJT4BXU1yKxvAKUvLMa X2Tuy2hbQvF2agQPWqDfSAbfgp1uHkNTHPL08NZOvMSlhI7JAbet63OM7aPtKCfwnben v9MaUqxvDPZM3DrORbzaVGJCN6CKTEEjL4R/OHl+limG6b0e7f87gQxucJiryQ7T4ggb H+Jw== X-Gm-Message-State: AGi0PuZLnDYyILcRcGZaPH6SDHgboBx8KONcQkKUUgI2a1DqJSdmcTXZ LsH+dJpLlL3xY5aAWOuli1yMIS1qyKLIr1aSNKUFHATZefg= X-Received: by 2002:a1c:7f91:: with SMTP id a139mr10008195wmd.164.1588860401319; Thu, 07 May 2020 07:06:41 -0700 (PDT) MIME-Version: 1.0 References: <20200507140139.17083-1-david@redhat.com> <20200507140139.17083-12-david@redhat.com> In-Reply-To: <20200507140139.17083-12-david@redhat.com> From: Pankaj Gupta Date: Thu, 7 May 2020 16:06:30 +0200 Message-ID: Subject: Re: [PATCH v4 11/15] virtio-mem: Add parent resource for all added "System RAM" To: David Hildenbrand Cc: LKML , Linux MM , virtio-dev@lists.oasis-open.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, Michal Hocko , Andrew Morton , "Michael S . Tsirkin" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > Let's add a parent resource, named after the virtio device (inspired by > drivers/dax/kmem.c). This allows user space to identify which memory > belongs to which virtio-mem device. > > With this change and two virtio-mem devices: > :/# cat /proc/iomem > 00000000-00000fff : Reserved > 00001000-0009fbff : System RAM > [...] > 140000000-333ffffff : virtio0 > 140000000-147ffffff : System RAM > 148000000-14fffffff : System RAM > 150000000-157ffffff : System RAM > [...] > 334000000-3033ffffff : virtio1 > 338000000-33fffffff : System RAM > 340000000-347ffffff : System RAM > 348000000-34fffffff : System RAM > [...] > > Cc: "Michael S. Tsirkin" > Cc: Pankaj Gupta > Signed-off-by: David Hildenbrand > --- > drivers/virtio/virtio_mem.c | 52 ++++++++++++++++++++++++++++++++++++- > 1 file changed, 51 insertions(+), 1 deletion(-) > > diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c > index eb4c16d634e0..80cdb9e6b3c4 100644 > --- a/drivers/virtio/virtio_mem.c > +++ b/drivers/virtio/virtio_mem.c > @@ -99,6 +99,9 @@ struct virtio_mem { > /* Id of the next memory bock to prepare when needed. */ > unsigned long next_mb_id; > > + /* The parent resource for all memory added via this device. */ > + struct resource *parent_resource; > + > /* Summary of all memory block states. */ > unsigned long nb_mb_state[VIRTIO_MEM_MB_STATE_COUNT]; > #define VIRTIO_MEM_NB_OFFLINE_THRESHOLD 10 > @@ -1741,6 +1744,44 @@ static int virtio_mem_init(struct virtio_mem *vm) > return 0; > } > > +static int virtio_mem_create_resource(struct virtio_mem *vm) > +{ > + /* > + * When force-unloading the driver and removing the device, we > + * could have a garbage pointer. Duplicate the string. > + */ > + const char *name = kstrdup(dev_name(&vm->vdev->dev), GFP_KERNEL); > + > + if (!name) > + return -ENOMEM; > + > + vm->parent_resource = __request_mem_region(vm->addr, vm->region_size, > + name, IORESOURCE_SYSTEM_RAM); > + if (!vm->parent_resource) { > + kfree(name); > + dev_warn(&vm->vdev->dev, "could not reserve device region\n"); > + return -EBUSY; > + } > + > + /* The memory is not actually busy - make add_memory() work. */ > + vm->parent_resource->flags &= ~IORESOURCE_BUSY; > + return 0; > +} > + > +static void virtio_mem_delete_resource(struct virtio_mem *vm) > +{ > + const char *name; > + > + if (!vm->parent_resource) > + return; > + > + name = vm->parent_resource->name; > + release_resource(vm->parent_resource); > + kfree(vm->parent_resource); > + kfree(name); > + vm->parent_resource = NULL; > +} > + > static int virtio_mem_probe(struct virtio_device *vdev) > { > struct virtio_mem *vm; > @@ -1770,11 +1811,16 @@ static int virtio_mem_probe(struct virtio_device *vdev) > if (rc) > goto out_del_vq; > > + /* create the parent resource for all memory */ > + rc = virtio_mem_create_resource(vm); > + if (rc) > + goto out_del_vq; > + > /* register callbacks */ > vm->memory_notifier.notifier_call = virtio_mem_memory_notifier_cb; > rc = register_memory_notifier(&vm->memory_notifier); > if (rc) > - goto out_del_vq; > + goto out_del_resource; > rc = register_virtio_mem_device(vm); > if (rc) > goto out_unreg_mem; > @@ -1788,6 +1834,8 @@ static int virtio_mem_probe(struct virtio_device *vdev) > return 0; > out_unreg_mem: > unregister_memory_notifier(&vm->memory_notifier); > +out_del_resource: > + virtio_mem_delete_resource(vm); > out_del_vq: > vdev->config->del_vqs(vdev); > out_free_vm: > @@ -1848,6 +1896,8 @@ static void virtio_mem_remove(struct virtio_device *vdev) > vm->nb_mb_state[VIRTIO_MEM_MB_STATE_ONLINE_PARTIAL] || > vm->nb_mb_state[VIRTIO_MEM_MB_STATE_ONLINE_MOVABLE]) > dev_warn(&vdev->dev, "device still has system memory added\n"); > + else > + virtio_mem_delete_resource(vm); > > /* remove all tracking data - no locking needed */ > vfree(vm->mb_state); > -- Reviewed-by: Pankaj Gupta