From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 95D15A00BE for ; Thu, 21 Apr 2022 15:19:06 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 899C0427EE; Thu, 21 Apr 2022 15:19:06 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id B6D3D40040; Thu, 21 Apr 2022 15:19:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650547143; x=1682083143; h=message-id:date:subject:to:cc:references:from: in-reply-to:content-transfer-encoding:mime-version; bh=PyoXgUoILJQPS7r/z3SYc6h9lCffBDLejxhNwA3j5kA=; b=dZ1vjSi1zKIBWD44DyIfFIgtpU039K6fAsmBV6Y1xS1Dzzo0JavyZtMr hXTn3YelO/nFu48DtWizZZhN1nxqONN6toMOimzpC+2g0Iy/RegbqHFEd mIo3pWtYfwZXrfewRs7Jk7yT5Qc40miCrLXqUXHP2qkem1NlhtV4gxUyn 1IUjtMORUUt0jEM59FD8Z07pKBRKCbNzwCHI1QG0rr/GH5wfF8Z0EfvjX oq5I/KQlLSMT9JP46Fen7+EFRJoIlwJI/A0EfOfLpCLI5yuUeNS/5p0gH QmFYbRNoHeEEL8HiGuDeXOy1Wxr+hRnNMZDIMQz8Ykg8rLfga3/osN1s5 w==; X-IronPort-AV: E=McAfee;i="6400,9594,10323"; a="327251331" X-IronPort-AV: E=Sophos;i="5.90,278,1643702400"; d="scan'208";a="327251331" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2022 06:19:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,278,1643702400"; d="scan'208";a="614885727" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by fmsmga008.fm.intel.com with ESMTP; 21 Apr 2022 06:19:01 -0700 Received: from orsmsx606.amr.corp.intel.com (10.22.229.19) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Thu, 21 Apr 2022 06:19:00 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx606.amr.corp.intel.com (10.22.229.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27 via Frontend Transport; Thu, 21 Apr 2022 06:19:00 -0700 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.100) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.27; Thu, 21 Apr 2022 06:19:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BFStmksRQwA9H73QUiVs1gRcrQZMW2VjcDH57bAGaBEVOx/Ec9shVNefwBMPwUZF8WbQHivwVl9WUMDzWsGPYxKnDkjTeSVAjGL12oVbF5jIWaOE3kvHNOUan6q9ItvmwgKZNPwBrjIEUuXnCG4rzrRqnk6EA/ibMRRAtJCOoHjCW+ag4ljQJRPUMmYFH5ll/EjPKCQGgS0cQdrSXT0a4jLZ2hkt6zOMWnU+pBXknE6zVL5FJYlhGtymc3yt3PVtspWw2vOKbFhDjxv3XE5gZ4RXfM6q6ROxXbrnLvnx/o5isuj991CtsVzZ7xhOpU0+HqIbX3oD3lAojy6HQc5Q2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SXSdpj9lctIgeh/tJYOCzTadEagw3H1QrqAeIDWNbSo=; b=EuOKUS4opzwFM7dOMKfREpuZzfxcdB8oUjTBBhUvrMYvRT7vOW7qVEp7LS7+aPPj/27oGCIfi4fdzjV+O/SB/Y6Uyx9cyH6VrsMtaKRaQfkvGD8xCNSZUzmY892uL4wlxxsxFVfwXhvyLOCb6Eiz9mZiDLE3dU3LGfFCKFLFHcHKTQF2KZxeXy4IqFIAWXuJpCiiZ4UZF5QXr4I/giaDJMH8HkEPWKf2geYpWFaw71HDaZcDCZ3WcOxwU5pYZ1ae2LD4wDMdQbV1p0740kjHHlfyTtsGlIo1xqVkt8kocAEnS5PnZsTJcRjA6IDxELw2uMBWUHmWcpvWeA1xYzjDVQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from PH0PR11MB5093.namprd11.prod.outlook.com (2603:10b6:510:3e::23) by DS7PR11MB6063.namprd11.prod.outlook.com (2603:10b6:8:76::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.13; Thu, 21 Apr 2022 13:18:59 +0000 Received: from PH0PR11MB5093.namprd11.prod.outlook.com ([fe80::28af:8ec5:1817:1af1]) by PH0PR11MB5093.namprd11.prod.outlook.com ([fe80::28af:8ec5:1817:1af1%3]) with mapi id 15.20.5186.015; Thu, 21 Apr 2022 13:18:58 +0000 Message-ID: Date: Thu, 21 Apr 2022 14:18:53 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0 Thunderbird/91.7.0 Subject: Re: [PATCH 2/3] mem: fix ASan shadow for remapped memory segments Content-Language: en-US To: David Marchand CC: dev , "Mcnamara, John" , "Dmitry Kozlyuk" , dpdk stable , Xueqin Lin References: <20220415173127.3838-1-david.marchand@redhat.com> <20220415173127.3838-3-david.marchand@redhat.com> <419bb7fc-cb04-10cf-a40a-5dba39323f9e@intel.com> From: "Burakov, Anatoly" In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO2P265CA0459.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a2::15) To PH0PR11MB5093.namprd11.prod.outlook.com (2603:10b6:510:3e::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 60957b00-88e2-41c9-3e97-08da23997e78 X-MS-TrafficTypeDiagnostic: DS7PR11MB6063:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mpRrCGm7RAXbKdyHwtyQpxDMeRIVF4Z9F0BMmqSMvqgUEaPUfHnm8qzzTvXOduyAtjA5J8UlqqYmydfkLl8XhzvUmwVSshQsk0kbwvj5X3t+9HHgUfsg93k4v2xzqYkBf+tA0W4/kRxyHOkcE+/HzW7P7eMHduolgqB7h/q8JXtJhNum5U/OMlvO4K88xxef4npShwvHHWkKDWknK4+gddCTJn+iHZ4WXxB3kqWCuNknBKCv4v90gq6XIhhbt+e5TMB4woNth/kuLjxbaJmcgUaSGVainiF498AVPwbFLEoUrthH1z8Et0f/+2Xuw7wJ9rmOk1GLPjepGKt0HWJqzojiLStV3I9joGt4VNv1b/B4ttq/fhXI4xlZLaGirNXP7mpM9XFaqA8cEqJ0iuGrdZaYequD072OI82vyCoenOrQisdJlVuWP3uHsY+/PN55DTbjyAL5xKA1m32RvGe5SkUPFpzpGDHP3wJV9A1bneGlrkyoqvm0uMvhgvDCoxLy41OqybSpWQi575hQYZT1REBzHRGJI3XRcwIUCfRKvLbt4kdszqOsY64hGekqnirdvvlpOKNyeb4FrisI/W6NnH4WAy1YbRYpCQvs2EYewvwgug8eMe5Hsgyk1G/pWEDWt+W/pbvGpsb/x6wVqSAjK679I+DdAYhItVncc5eEPEPyc0cMYgAONt2lw9lvB/WsIA7YfjGWG694cJycjHjxdfEL5xB2OR7Kym/bCSr9IKY= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR11MB5093.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(38100700002)(8936002)(82960400001)(83380400001)(5660300002)(508600001)(86362001)(186003)(31696002)(316002)(6486002)(2616005)(26005)(53546011)(2906002)(6506007)(8676002)(4326008)(66476007)(66556008)(66946007)(54906003)(107886003)(36756003)(6666004)(6512007)(6916009)(31686004)(43740500002)(45980500001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?RnRlUm0xWmZLc1gzd3pORVhEOUEwcHJLRDkxZmxXYkRSQzIxRnlJc1NhczBT?= =?utf-8?B?dCs1eUUwOU43TGo2OHhNZ3o2dnp2TFlJeHZDK29SZkVlL2dsVjJIa08xNVRM?= =?utf-8?B?aHQyM3FxRDY4SnBiUFhJNFV0RitkOWdUR1hkZHJOL2ZmYzBhYVlTbmVqUmFp?= =?utf-8?B?SE5aY2o0NlI5SnlZZ2pwVXBMTjdqcXdWWHNQV0R2UnV5NU1pUGgwcmpublk2?= =?utf-8?B?TkdWSWMzVERsTzRBTldkQnpNSDhkVXVtbVQweXc1WWhkRW14OXNDclNaRHpx?= =?utf-8?B?MnhCdi9EUkRTNm5jeHBvYmZiaEpMUzIzNGpIUmU3d3J1b1VpTk1oNkJycW5a?= =?utf-8?B?bkNSUE04S1FIZUw0M1NXWlhXZkx0QmJtQU0vMk5aQmI5MTBVK3VEZ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NnTFlLS1o0MmNDUGFvWENaVHRyOXphS2dvVEpr?= =?utf-8?B?QllENHYxSnJkYlo0RERtWGluWmlOV2dtWUs2YXhiMzRjTzZLMVdiOHpKY0JI?= =?utf-8?B?UmpxZEF2cE1oVWI5TUN3cTdlLzNDUFUzYlVKeEVKcXROTnlCRlA0MHk4dlAx?= =?utf-8?Q?Pnc85DC2eOupRorU=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 60957b00-88e2-41c9-3e97-08da23997e78 X-MS-Exchange-CrossTenant-AuthSource: PH0PR11MB5093.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Apr 2022 13:18:58.7936 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: M6HKtIMmBJ7AsX0Pg8kFVrYpA7y5GD+Xz89VbKMP0fS4TSoNE12jUNl2SBV6fN2r0nYatjwWUz9JPa02kaiZ1VsQAmpeJvghl27SJhZbdw4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR11MB6063 X-OriginatorOrg: intel.com X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org On 21-Apr-22 10:37 AM, David Marchand wrote: > On Wed, Apr 20, 2022 at 4:47 PM Burakov, Anatoly > wrote: >> >> On 15-Apr-22 6:31 PM, David Marchand wrote: >>> When releasing some memory, the allocator can choose to return some >>> pages to the OS. At the same time, this memory was poisoned in ASAn >>> shadow. Doing the latter made it impossible to remap this same page >>> later. >>> On the other hand, without this poison, the OS would pagefault in any >>> case for this page. >>> >>> Remove the poisoning for unmapped pages. >>> >>> Bugzilla ID: 994 >>> Fixes: 6cc51b1293ce ("mem: instrument allocator for ASan") >>> Cc: stable@dpdk.org >>> >>> Signed-off-by: David Marchand >>> --- >>> lib/eal/common/malloc_elem.h | 4 ++++ >>> lib/eal/common/malloc_heap.c | 12 +++++++++++- >>> 2 files changed, 15 insertions(+), 1 deletion(-) >>> >>> diff --git a/lib/eal/common/malloc_elem.h b/lib/eal/common/malloc_elem.h >>> index 228f178418..b859003722 100644 >>> --- a/lib/eal/common/malloc_elem.h >>> +++ b/lib/eal/common/malloc_elem.h >>> @@ -272,6 +272,10 @@ old_malloc_size(struct malloc_elem *elem) >>> >>> #else /* !RTE_MALLOC_ASAN */ >>> >>> +static inline void >>> +asan_set_zone(void *ptr __rte_unused, size_t len __rte_unused, >>> + uint32_t val __rte_unused) { } >>> + >>> static inline void >>> asan_set_freezone(void *ptr __rte_unused, size_t size __rte_unused) { } >>> >>> diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c >>> index 6c572b6f2c..5913d9f862 100644 >>> --- a/lib/eal/common/malloc_heap.c >>> +++ b/lib/eal/common/malloc_heap.c >>> @@ -860,6 +860,7 @@ malloc_heap_free(struct malloc_elem *elem) >>> size_t len, aligned_len, page_sz; >>> struct rte_memseg_list *msl; >>> unsigned int i, n_segs, before_space, after_space; >>> + bool unmapped_pages = false; >>> int ret; >>> const struct internal_config *internal_conf = >>> eal_get_internal_configuration(); >>> @@ -999,6 +1000,13 @@ malloc_heap_free(struct malloc_elem *elem) >>> >>> /* don't care if any of this fails */ >>> malloc_heap_free_pages(aligned_start, aligned_len); >>> + /* >>> + * Clear any poisoning in ASan for the associated pages so that >>> + * next time EAL maps those pages, the allocator can access >>> + * them. >>> + */ >>> + asan_set_zone(aligned_start, aligned_len, 0x00); >>> + unmapped_pages = true; >>> >>> request_sync(); >>> } else { >>> @@ -1032,7 +1040,9 @@ malloc_heap_free(struct malloc_elem *elem) >>> >>> rte_mcfg_mem_write_unlock(); >>> free_unlock: >>> - asan_set_freezone(asan_ptr, asan_data_len); >>> + /* Poison memory range if belonging to some still mapped pages. */ >>> + if (!unmapped_pages) >>> + asan_set_freezone(asan_ptr, asan_data_len); >>> >>> rte_spinlock_unlock(&(heap->lock)); >>> return ret; >> >> I suspect the patch should be a little more complicated than that. When >> we unmap pages, we don't necessarily unmap the entire malloc element, it >> could be that we have a freed allocation like so: >> >> | malloc header | free space | unmapped space | free space | next malloc >> header | >> >> So, i think the freezone should be set from asan_ptr till aligned_start, >> and then from (aligned_start + aligned_len) till (asan_ptr + >> asan_data_len). Does that make sense? > > (btw, I get a bounce for Zhihong mail address, is he not working at > Intel anymore?) > > To be honest, I don't understand if we can get to this situation :-) > (especially the free space after the unmapped region). > But I guess you mean something like (on top of current patch): > > @@ -1040,9 +1040,25 @@ malloc_heap_free(struct malloc_elem *elem) > > rte_mcfg_mem_write_unlock(); > free_unlock: > - /* Poison memory range if belonging to some still mapped pages. */ > - if (!unmapped_pages) > + if (!unmapped_pages) { > asan_set_freezone(asan_ptr, asan_data_len); > + } else { > + /* > + * We may be in a situation where we unmapped pages like this: > + * malloc header | free space | unmapped space | free > space | malloc header > + */ > + void *free1_start = asan_ptr; > + void *free1_end = aligned_start; > + void *free2_start = RTE_PTR_ADD(aligned_start, aligned_len); > + void *free2_end = RTE_PTR_ADD(asan_ptr, asan_data_len); > + > + if (free1_start < free1_end) > + asan_set_freezone(free1_start, > + RTE_PTR_DIFF(free1_end, free1_start)); > + if (free2_start < free2_end) > + asan_set_freezone(free2_start, > + RTE_PTR_DIFF(free2_end, free2_start)); > + } > > rte_spinlock_unlock(&(heap->lock)); > return ret; > Something like that, yes. I will have to think through this a bit more, especially in light of your func_reentrancy splat :) -- Thanks, Anatoly