Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp709249yba; Thu, 16 May 2019 07:45:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqwBiuhoE56is9aAGg10oBQLbGWUsOqZqUDNrw90ApCV3/KqTVOTgbikGvXu6aWFKhTbOd72 X-Received: by 2002:a65:60c7:: with SMTP id r7mr48900117pgv.22.1558017912920; Thu, 16 May 2019 07:45:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558017912; cv=none; d=google.com; s=arc-20160816; b=BFFJvL3KUMadqAVuLGEZCLaJm0W32PEjl/5LdkvrYiJFKwBGrfEOslcl1BNRqM4uWR Z679jzvvX6wLSDXfwLn9F7GaqjjCHJkBlsXL74Hw4Y7v3sKjR9qb1MHUc8nUyNlm8N82 5o8zwlCdEYWOmmqVF6hNu0Vt35y/2g03528+NgB7vR93u351XD87Nkkv9Asj7NJKliy+ vV+i2vh09Esjw5h/d4MJkEF8XqV9IdN95GxT4/LcpIYa+2IgdXHQIHFNi6QyGhpQVVto Sx+kW6cMbLZKVPR6UP7+XHyxw4CBkafJCo3JlsHPJ7JKWHYOoqH73TbWNtFzHTFS7R2A 9tcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Cj+rXNfNlUN3r4Yp7FC3w8W2jv87lre7M4pXy1RJygg=; b=jnpJUjLqOmBUzTY6rD+zLi/nmpq9v61OsyX7SVaUN6xMR9eGyQFwK4Tmj3Kg0pc7nB tXPtThjFJdIMT6AzeYsgD9XLNgLNMaWuirWY9q9dLpVqodvzU+nAFFtZ/lTLuCg1xFpv 8OpnoBBPQirfUDsXxdNP2345/uSv2JuthDMzZxk4yJHgVT5s6hCyUhA8jIqLJRsn8fFg Zz4gzPIjDC646fFydpfqS0pGBazBFRhi9pG5jK/WW3IH9sPLMetGfvWEzlfc0ojrewtf 0uqRn1UaXZsigFomMnFYykRCdnQFHvoOLJAqRCGX/uM3wbxi5r/mb/ys3BXC5IvSCc05 CRUA== ARC-Authentication-Results: i=1; mx.google.com; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s4si4885882plp.59.2019.05.16.07.44.56; Thu, 16 May 2019 07:45:12 -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; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727467AbfEPOn2 (ORCPT + 99 others); Thu, 16 May 2019 10:43:28 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:35255 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727401AbfEPOn1 (ORCPT ); Thu, 16 May 2019 10:43:27 -0400 Received: by mail-wr1-f65.google.com with SMTP id m3so3551903wrv.2 for ; Thu, 16 May 2019 07:43:26 -0700 (PDT) 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:user-agent; bh=Cj+rXNfNlUN3r4Yp7FC3w8W2jv87lre7M4pXy1RJygg=; b=S6+iqijnJucwreWKxlpYkRrSVGQK1pNor13wssFA/H0y8dBClJmFrCrVxTeUYizJrD OoejWbW5q/7zNxWTwDVghddMUrDAq7vrw6DwEPXUF5vtSVE7dF9iZrAtE+oiVO76c4I8 UUB+BHAVuPtK/YQWdcYEc/RrJ1byYPUrt3mIE2yNiaK2nSvMSoZMWy6/S/OoPm3QYNMF +6ZkJlZE3JDU2zmNSDKoWRW+w/rTDxBU05354TVJmAnR6dax5apuM/E7/aP4tJA7uvjV 2swpOL3vmwzk0e2EyPA4/uFaIV4Hx5Q54Q9XKKJ3/DETbN1biKHDw/WC3VNGuIAzedIO LRQw== X-Gm-Message-State: APjAAAX13thBNkfsBkJFhZGCVy/zynQGwmb+gXQ5UC0ZwTqnN9ZrK0Tr j9beSdA1vPFVO9g6TpORZ/cX0w== X-Received: by 2002:a5d:4206:: with SMTP id n6mr17691401wrq.58.1558017806003; Thu, 16 May 2019 07:43:26 -0700 (PDT) Received: from localhost (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id q13sm6113444wrn.27.2019.05.16.07.43.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 16 May 2019 07:43:25 -0700 (PDT) Date: Thu, 16 May 2019 16:43:24 +0200 From: Oleksandr Natalenko To: Jann Horn Cc: kernel list , Kirill Tkhai , Hugh Dickins , Alexey Dobriyan , Vlastimil Babka , Michal Hocko , Matthew Wilcox , Pavel Tatashin , Greg KH , Suren Baghdasaryan , Minchan Kim , Timofey Titovets , Aaron Tomlin , Grzegorz Halat , Linux-MM , Linux API Subject: Re: [PATCH RFC 4/5] mm/ksm, proc: introduce remote merge Message-ID: <20190516144323.pzkvs6hapf3czorz@butterfly.localdomain> References: <20190516094234.9116-1-oleksandr@redhat.com> <20190516094234.9116-5-oleksandr@redhat.com> <20190516142013.sf2vitmksvbkb33f@butterfly.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190516142013.sf2vitmksvbkb33f@butterfly.localdomain> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 16, 2019 at 04:20:13PM +0200, Oleksandr Natalenko wrote: > > [...] > > > @@ -2960,15 +2962,63 @@ static int proc_stack_depth(struct seq_file *m, struct pid_namespace *ns, > > > static ssize_t madvise_write(struct file *file, const char __user *buf, > > > size_t count, loff_t *ppos) > > > { > > > + /* For now, only KSM hints are implemented */ > > > +#ifdef CONFIG_KSM > > > + char buffer[PROC_NUMBUF]; > > > + int behaviour; > > > struct task_struct *task; > > > + struct mm_struct *mm; > > > + int err = 0; > > > + struct vm_area_struct *vma; > > > + > > > + memset(buffer, 0, sizeof(buffer)); > > > + if (count > sizeof(buffer) - 1) > > > + count = sizeof(buffer) - 1; > > > + if (copy_from_user(buffer, buf, count)) > > > + return -EFAULT; > > > + > > > + if (!memcmp("merge", buffer, min(sizeof("merge")-1, count))) > > > > This means that you also match on something like "mergeblah". Just use strcmp(). > > I agree. Just to make it more interesting I must say that > > /sys/kernel/mm/transparent_hugepage/enabled > > uses memcmp in the very same way, and thus echoing "alwaysssss" or > "madviseeee" works perfectly there, and it was like that from the very > beginning, it seems. Should we fix it, or it became (zomg) a public API? Actually, maybe, the reason for using memcmp is to handle "echo" properly: by default it puts a newline character at the end, so if we use just strcmp, echo should be called with -n, otherwise strcmp won't match the string. Huh? > [...] -- Best regards, Oleksandr Natalenko (post-factum) Senior Software Maintenance Engineer