Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp6819956ybh; Thu, 8 Aug 2019 06:13:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqyfxOLaYWKp4BbzMr3y4uE0JzPHq1Y3EbyRSZYU5ULVjY3dMi06g57ZBfjpKYi0LsDYM+l5 X-Received: by 2002:a17:902:e30d:: with SMTP id cg13mr13697681plb.173.1565269988825; Thu, 08 Aug 2019 06:13:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565269988; cv=none; d=google.com; s=arc-20160816; b=iSCHARbf6eIrzcpIQlkQHyIuUaEU6QJJ9g/V5AlJLx/ltnnR70djS6rBfFrkwfhiWl wUE1vjb5/vPbPqB7gG4D93uIgK8BboO3coJenEpRuPp8s/YCzRxWMFiaVz7D2+udmHJ4 1w5qjkqcrd+fI0ZK86Z++heZF5lRqB6uGZaib52xq3tLMMoMMLN45cZl/nTjRDqNWV5o 03CfDDTo9vqx0j+b1U+DeiDHjpA/jFTSuPG2NFKG8C2CeMETYblQAXJIIa59YSaEqjAc TrY2/pgfZDzIYn6XFGp3T/uCygbkfaeJchehQ627izilX35rw/lfBnRXegaZdTEazNJD fjOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:dkim-signature; bh=ghbafTZeER7tFVSxKR0FoUNjQNOkuIPxO4zFms6fLUg=; b=b0IfGcUpZbhy1K07FCrfGCOGBv9UtyPD6sezGoTRyT2obBPX2J8VJdHWfozWR+aGbT 1ruzVXqjvGdGGAOcQtRVnDFy74Q2XXHYp5axYCmh+l7VTID7D4+k2le+QQx5S16k7gQR 0r/nDN2JzOK2lvCdTXCadosmQmQwZNQvNaaoUD6q5//RB/j7FsgNmEKWkrjCiH0XsvuW 5OhuixsH03TQd9ZgeRgZRoakcN9E1/XpU9pFCgFUTZuD+uioSXGl+q1jvG/r+II0mlY2 Zc9FBkRflJaeHQBm4tTcU2tZp1xkjp4TVByit2c/Ew/MKwggsykwqLmDS+MosJ3lsNAx Subw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=HDAKTHGL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x21si47702131pln.397.2019.08.08.06.12.52; Thu, 08 Aug 2019 06:13:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=HDAKTHGL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732969AbfHHNLG (ORCPT + 99 others); Thu, 8 Aug 2019 09:11:06 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:37404 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732645AbfHHNLG (ORCPT ); Thu, 8 Aug 2019 09:11:06 -0400 Received: by mail-pf1-f194.google.com with SMTP id 19so44078856pfa.4; Thu, 08 Aug 2019 06:11:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ghbafTZeER7tFVSxKR0FoUNjQNOkuIPxO4zFms6fLUg=; b=HDAKTHGLr1vPMQY+1M6UtNpZ4aeffhDs6Ljt9HwWSKX66NP7I8ulEYeU3JHSfA7U4z L/lmA+ZPFy8xEfhQY/9tgoRPhcm17M29Hl/cbelWsrzDEtrazQlmLSLHuphKSBes3abF 5z2hjaD7/BicGKOen58Qi1gnUe69nFMu8mt0alEWPQX8TofJMEePz2LvW7hKz3UQUsfi KovTVAtUDnU/If8ePS/euYbFvhO9+A2GThccvjadlmLbouIyYRAgpgnvZTE6zrJSXhjg OhZtipnGYL6SJ5EDdw5Urtq4sD/HX8IOppoXkyXh8vlEEwzO6ZQCa2bv5r7x6b+C5sk/ EcWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ghbafTZeER7tFVSxKR0FoUNjQNOkuIPxO4zFms6fLUg=; b=UZO+PlRCgNq1Wm0LysUTfNBnEiYe8S2I8IgjmOG/C1OAEbsjGmGrAys5s+1oMOZdjr 1ie3UnbCgQ1jPtoUw0QP26rrSz/05KZI/WlTM6KMXVJB4iRzVzL2rIfL4Ch0CtgJuqbm un2qhric10uJSlKuDMegy3BeIoLnu+KFbmehLTICDl5/YVGNfl2pgp7NYgIEv/1Nn5bj e0nofB93vUdNULn878ly0NsRWLSNHgFT+86BDhYje2UKhcnnxK4p7grfFGO4qckNxt1J xGD2h0Lif4aLg0ngO75DQxp77RH+I65Ek3WcPjE4M8+cspLqhyh6GmRAHM5BtcFB70gd MbQg== X-Gm-Message-State: APjAAAUUj69VRgwREBjDr47235b5rIiktiAzaMjooqGm9XQ+MF50rzt5 tYTTbSRfANr1rcIS8C8lWlk= X-Received: by 2002:a62:5252:: with SMTP id g79mr15208485pfb.18.1565269865807; Thu, 08 Aug 2019 06:11:05 -0700 (PDT) Received: from suzukaze.ipads-lab.se.sjtu.edu.cn ([89.31.126.54]) by smtp.gmail.com with ESMTPSA id p67sm118773185pfg.124.2019.08.08.06.11.02 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 08 Aug 2019 06:11:05 -0700 (PDT) From: Chuhong Yuan Cc: Konrad Rzeszutek Wilk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Jens Axboe , xen-devel@lists.xenproject.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Chuhong Yuan Subject: [PATCH 3/3] xen/blkback: Use refcount_t for refcount Date: Thu, 8 Aug 2019 21:11:00 +0800 Message-Id: <20190808131100.24751-1-hslester96@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Reference counters are preferred to use refcount_t instead of atomic_t. This is because the implementation of refcount_t can prevent overflows and detect possible use-after-free. So convert atomic_t ref counters to refcount_t. Signed-off-by: Chuhong Yuan --- drivers/block/xen-blkback/common.h | 7 ++++--- drivers/block/xen-blkback/xenbus.c | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/block/xen-blkback/common.h b/drivers/block/xen-blkback/common.h index 1d3002d773f7..9db5f3586fb4 100644 --- a/drivers/block/xen-blkback/common.h +++ b/drivers/block/xen-blkback/common.h @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -309,7 +310,7 @@ struct xen_blkif { struct xen_vbd vbd; /* Back pointer to the backend_info. */ struct backend_info *be; - atomic_t refcnt; + refcount_t refcnt; /* for barrier (drain) requests */ struct completion drain_complete; atomic_t drain; @@ -362,10 +363,10 @@ struct pending_req { (_v)->bdev->bd_part->nr_sects : \ get_capacity((_v)->bdev->bd_disk)) -#define xen_blkif_get(_b) (atomic_inc(&(_b)->refcnt)) +#define xen_blkif_get(_b) (refcount_inc(&(_b)->refcnt)) #define xen_blkif_put(_b) \ do { \ - if (atomic_dec_and_test(&(_b)->refcnt)) \ + if (refcount_dec_and_test(&(_b)->refcnt)) \ schedule_work(&(_b)->free_work);\ } while (0) diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index 3ac6a5d18071..ecc5f9c5bf3f 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -169,7 +169,7 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid) return ERR_PTR(-ENOMEM); blkif->domid = domid; - atomic_set(&blkif->refcnt, 1); + refcount_set(&blkif->refcnt, 1); init_completion(&blkif->drain_complete); INIT_WORK(&blkif->free_work, xen_blkif_deferred_free); -- 2.20.1